Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Dec 12, 2019
1 parent 6eb4ac7 commit a235718
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,38 +41,38 @@
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;


@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());
Expand All @@ -81,83 +81,83 @@ public void setupActivitiesPresenter() {
@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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,7 +42,7 @@ public class RemoteActivitiesRepositoryTest {
ActivitiesRepository.LoadActivitiesCallback mockedLoadActivitiesCallback;

@Mock
OwnCloudClient ownCloudClient;
NextcloudClient nextcloudClient;

@Captor
private ArgumentCaptor<ActivitiesServiceApi.ActivitiesServiceCallback> activitiesServiceCallbackCaptor;
Expand All @@ -62,8 +62,8 @@ public void setUpActivitiesRepository() {
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
Expand Down

0 comments on commit a235718

Please sign in to comment.