mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
fix tests
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
6eb4ac7c47
commit
a2357181ab
2 changed files with 48 additions and 48 deletions
|
@ -18,8 +18,8 @@
|
|||
*/
|
||||
package com.owncloud.android.ui.activities;
|
||||
|
||||
import com.nextcloud.common.NextcloudClient;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.resources.activities.model.Activity;
|
||||
import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository;
|
||||
import com.owncloud.android.ui.activities.data.files.FilesRepository;
|
||||
|
@ -41,30 +41,30 @@ import static org.mockito.Mockito.verify;
|
|||
public class ActivitiesPresenterTest {
|
||||
|
||||
@Mock
|
||||
private FilesRepository mFileRepository;
|
||||
private FilesRepository filesRepository;
|
||||
|
||||
@Mock
|
||||
private ActivitiesContract.View mView;
|
||||
private ActivitiesContract.View view;
|
||||
|
||||
@Mock
|
||||
private ActivitiesRepository mActivitiesRepository;
|
||||
private ActivitiesRepository activitiesRepository;
|
||||
|
||||
@Mock
|
||||
private BaseActivity mBaseActivity;
|
||||
private BaseActivity baseActivity;
|
||||
|
||||
@Mock
|
||||
private OwnCloudClient mOwnCloudClient;
|
||||
private NextcloudClient nextcloudClient;
|
||||
|
||||
@Mock
|
||||
private OCFile mOCFile;
|
||||
private OCFile ocFile;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<FilesRepository.ReadRemoteFileCallback> mReadRemoteFilleCallbackCaptor;
|
||||
private ArgumentCaptor<FilesRepository.ReadRemoteFileCallback> readRemoteFileCallbackArgumentCaptor;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<ActivitiesRepository.LoadActivitiesCallback> mLoadActivitiesCallbackCaptor;
|
||||
private ArgumentCaptor<ActivitiesRepository.LoadActivitiesCallback> loadActivitiesCallbackArgumentCaptor;
|
||||
|
||||
private ActivitiesPresenter mPresenter;
|
||||
private ActivitiesPresenter activitiesPresenter;
|
||||
|
||||
private List<Object> activitiesList;
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class ActivitiesPresenterTest {
|
|||
@Before
|
||||
public void setupActivitiesPresenter() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mPresenter = new ActivitiesPresenter(mActivitiesRepository, mFileRepository, mView);
|
||||
activitiesPresenter = new ActivitiesPresenter(activitiesRepository, filesRepository, view);
|
||||
|
||||
activitiesList = new ArrayList<>();
|
||||
activitiesList.add(new Activity());
|
||||
|
@ -81,83 +81,83 @@ public class ActivitiesPresenterTest {
|
|||
@Test
|
||||
public void loadActivitiesFromRepositoryIntoView() {
|
||||
// When loading activities from repository is requested from presenter...
|
||||
mPresenter.loadActivities(-1);
|
||||
activitiesPresenter.loadActivities(-1);
|
||||
// Progress indicator is shown in view
|
||||
verify(mView).setProgressIndicatorState(eq(true));
|
||||
verify(view).setProgressIndicatorState(eq(true));
|
||||
// Repository starts retrieving activities from server
|
||||
verify(mActivitiesRepository).getActivities(eq(-1), mLoadActivitiesCallbackCaptor.capture());
|
||||
verify(activitiesRepository).getActivities(eq(-1), loadActivitiesCallbackArgumentCaptor.capture());
|
||||
// Repository returns data
|
||||
mLoadActivitiesCallbackCaptor.getValue().onActivitiesLoaded(activitiesList, mOwnCloudClient, -1);
|
||||
loadActivitiesCallbackArgumentCaptor.getValue().onActivitiesLoaded(activitiesList, nextcloudClient, -1);
|
||||
// Progress indicator is hidden
|
||||
verify(mView).setProgressIndicatorState(eq(false));
|
||||
verify(view).setProgressIndicatorState(eq(false));
|
||||
// List of activities is shown in view.
|
||||
verify(mView).showActivities(eq(activitiesList), eq(mOwnCloudClient), eq(-1));
|
||||
verify(view).showActivities(eq(activitiesList), eq(nextcloudClient), eq(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadActivitiesFromRepositoryShowError() {
|
||||
// When loading activities from repository is requested from presenter...
|
||||
mPresenter.loadActivities(-1);
|
||||
activitiesPresenter.loadActivities(-1);
|
||||
// Progress indicator is shown in view
|
||||
verify(mView).setProgressIndicatorState(eq(true));
|
||||
verify(view).setProgressIndicatorState(eq(true));
|
||||
// Repository starts retrieving activities from server
|
||||
verify(mActivitiesRepository).getActivities(eq(-1), mLoadActivitiesCallbackCaptor.capture());
|
||||
verify(activitiesRepository).getActivities(eq(-1), loadActivitiesCallbackArgumentCaptor.capture());
|
||||
// Repository returns data
|
||||
mLoadActivitiesCallbackCaptor.getValue().onActivitiesLoadedError("error");
|
||||
loadActivitiesCallbackArgumentCaptor.getValue().onActivitiesLoadedError("error");
|
||||
// Progress indicator is hidden
|
||||
verify(mView).setProgressIndicatorState(eq(false));
|
||||
verify(view).setProgressIndicatorState(eq(false));
|
||||
// Correct error is shown in view
|
||||
verify(mView).showActivitiesLoadError(eq("error"));
|
||||
verify(view).showActivitiesLoadError(eq("error"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadRemoteFileFromRepositoryShowDetailUI() {
|
||||
// When retrieving remote file from repository...
|
||||
mPresenter.openActivity("null", mBaseActivity);
|
||||
activitiesPresenter.openActivity("null", baseActivity);
|
||||
// Progress indicator is shown in view
|
||||
verify(mView).setProgressIndicatorState(eq(true));
|
||||
verify(view).setProgressIndicatorState(eq(true));
|
||||
// Repository retrieves remote file
|
||||
verify(mFileRepository).readRemoteFile(eq("null"), eq(mBaseActivity),
|
||||
mReadRemoteFilleCallbackCaptor.capture());
|
||||
verify(filesRepository).readRemoteFile(eq("null"), eq(baseActivity),
|
||||
readRemoteFileCallbackArgumentCaptor.capture());
|
||||
// Repository returns valid file object
|
||||
mReadRemoteFilleCallbackCaptor.getValue().onFileLoaded(mOCFile);
|
||||
readRemoteFileCallbackArgumentCaptor.getValue().onFileLoaded(ocFile);
|
||||
// Progress indicator is hidden
|
||||
verify(mView).setProgressIndicatorState(eq(false));
|
||||
verify(view).setProgressIndicatorState(eq(false));
|
||||
// File detail UI is shown
|
||||
verify(mView).showActivityDetailUI(eq(mOCFile));
|
||||
verify(view).showActivityDetailUI(eq(ocFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadRemoteFileFromRepositoryShowEmptyFile() {
|
||||
// When retrieving remote file from repository...
|
||||
mPresenter.openActivity("null", mBaseActivity);
|
||||
activitiesPresenter.openActivity("null", baseActivity);
|
||||
// Progress indicator is shown in view
|
||||
verify(mView).setProgressIndicatorState(eq(true));
|
||||
verify(view).setProgressIndicatorState(eq(true));
|
||||
// Repository retrieves remote file
|
||||
verify(mFileRepository).readRemoteFile(eq("null"), eq(mBaseActivity),
|
||||
mReadRemoteFilleCallbackCaptor.capture());
|
||||
verify(filesRepository).readRemoteFile(eq("null"), eq(baseActivity),
|
||||
readRemoteFileCallbackArgumentCaptor.capture());
|
||||
// Repository returns an valid but Null value file object.
|
||||
mReadRemoteFilleCallbackCaptor.getValue().onFileLoaded(null);
|
||||
readRemoteFileCallbackArgumentCaptor.getValue().onFileLoaded(null);
|
||||
// Progress indicator is hidden
|
||||
verify(mView).setProgressIndicatorState(eq(false));
|
||||
verify(view).setProgressIndicatorState(eq(false));
|
||||
// Returned file is null. Inform user.
|
||||
verify(mView).showActivityDetailUIIsNull();
|
||||
verify(view).showActivityDetailUIIsNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadRemoteFileFromRepositoryShowError() {
|
||||
// When retrieving remote file from repository...
|
||||
mPresenter.openActivity("null", mBaseActivity);
|
||||
activitiesPresenter.openActivity("null", baseActivity);
|
||||
// Progress indicator is shown in view
|
||||
verify(mView).setProgressIndicatorState(eq(true));
|
||||
verify(view).setProgressIndicatorState(eq(true));
|
||||
// Repository retrieves remote file
|
||||
verify(mFileRepository).readRemoteFile(eq("null"), eq(mBaseActivity),
|
||||
mReadRemoteFilleCallbackCaptor.capture());
|
||||
verify(filesRepository).readRemoteFile(eq("null"), eq(baseActivity),
|
||||
readRemoteFileCallbackArgumentCaptor.capture());
|
||||
// Repository returns valid file object
|
||||
mReadRemoteFilleCallbackCaptor.getValue().onFileLoadError("error");
|
||||
readRemoteFileCallbackArgumentCaptor.getValue().onFileLoadError("error");
|
||||
// Progress indicator is hidden
|
||||
verify(mView).setProgressIndicatorState(eq(false));
|
||||
verify(view).setProgressIndicatorState(eq(false));
|
||||
// Error message is shown to the user.
|
||||
verify(mView).showActivityDetailError(eq("error"));
|
||||
verify(view).showActivityDetailError(eq("error"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package com.owncloud.android.ui.activities.data.activities;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.nextcloud.common.NextcloudClient;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -42,7 +42,7 @@ public class RemoteActivitiesRepositoryTest {
|
|||
ActivitiesRepository.LoadActivitiesCallback mockedLoadActivitiesCallback;
|
||||
|
||||
@Mock
|
||||
OwnCloudClient ownCloudClient;
|
||||
NextcloudClient nextcloudClient;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<ActivitiesServiceApi.ActivitiesServiceCallback> activitiesServiceCallbackCaptor;
|
||||
|
@ -62,8 +62,8 @@ public class RemoteActivitiesRepositoryTest {
|
|||
public void loadActivitiesReturnSuccess() {
|
||||
mActivitiesRepository.getActivities(-1, mockedLoadActivitiesCallback);
|
||||
verify(serviceApi).getAllActivities(eq(-1), activitiesServiceCallbackCaptor.capture());
|
||||
activitiesServiceCallbackCaptor.getValue().onLoaded(activitiesList, ownCloudClient, -1);
|
||||
verify(mockedLoadActivitiesCallback).onActivitiesLoaded(eq(activitiesList), eq(ownCloudClient), eq(-1));
|
||||
activitiesServiceCallbackCaptor.getValue().onLoaded(activitiesList, nextcloudClient, -1);
|
||||
verify(mockedLoadActivitiesCallback).onActivitiesLoaded(eq(activitiesList), eq(nextcloudClient), eq(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue