Skip to content

Commit

Permalink
Adjust tests to new shouldInstanceBeRetained() method
Browse files Browse the repository at this point in the history
  • Loading branch information
sockeqwe committed Sep 1, 2015
1 parent e1fff88 commit fa95ee6
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ public class MvpFragmentTest {
PowerMockito.when(fragment.getRetainInstance()).thenReturn(true);
PowerMockito.when(fragment.getActivity()).thenReturn(null);

Assert.assertFalse(fragment.isRetainInstance());
Assert.assertFalse(fragment.shouldInstanceBeRetained());
}

@Test public void notRetainingAndActivityNull() {
PowerMockito.when(fragment.getRetainInstance()).thenReturn(false);
PowerMockito.when(fragment.getActivity()).thenReturn(null);

Assert.assertFalse(fragment.isRetainInstance());
Assert.assertFalse(fragment.shouldInstanceBeRetained());
}

@Test public void retainingAndNotChangingConfig() {
PowerMockito.when(fragment.getRetainInstance()).thenReturn(true);
PowerMockito.when(activity.isChangingConfigurations()).thenReturn(false);

Assert.assertFalse(fragment.isRetainInstance());
Assert.assertFalse(fragment.shouldInstanceBeRetained());
}

@Test public void retainingAndChangingConfig() {
Expand All @@ -74,6 +74,6 @@ public class MvpFragmentTest {
PowerMockito.when(fragment.getRetainInstance()).thenReturn(true);
PowerMockito.when(activity.isChangingConfigurations()).thenReturn(true);

Assert.assertTrue(fragment.isRetainInstance());
Assert.assertTrue(fragment.shouldInstanceBeRetained());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void reuseRetainingPresenter(){

private void testFinishActivity(boolean retainingInstanceState) {
Mockito.when(callback.getPresenter()).thenReturn(presenter);
Mockito.when(callback.isRetainInstance()).thenReturn(retainingInstanceState);
Mockito.when(callback.shouldInstanceBeRetained()).thenReturn(retainingInstanceState);

delegate.onPause();
delegate.onSaveInstanceState(new Bundle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void reuseRetainingPresenter(){

private void testFinishFragment(boolean retainingInstanceState) {
Mockito.when(callback.getPresenter()).thenReturn(presenter);
Mockito.when(callback.isRetainInstance()).thenReturn(retainingInstanceState);
Mockito.when(callback.shouldInstanceBeRetained()).thenReturn(retainingInstanceState);

delegate.onPause();
delegate.onSaveInstanceState(new Bundle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class MvpInternalDelegateTest {
@Test public void detachViewFromPresenterIsRetaining() {

Mockito.when(callback.getPresenter()).thenReturn(presenter);
Mockito.when(callback.isRetainInstance()).thenReturn(true);
Mockito.when(callback.shouldInstanceBeRetained()).thenReturn(true);

delegate.detachView();
Mockito.verify(presenter, Mockito.times(1)).detachView(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ public class ViewGroupMvpDelegateImplTest {

private void testFinishViewGroup(boolean retainingInstanceState) {
Mockito.when(callback.getPresenter()).thenReturn(presenter);
Mockito.when(callback.isRetainInstance()).thenReturn(retainingInstanceState);
Mockito.when(callback.shouldInstanceBeRetained()).thenReturn(retainingInstanceState);

delegate.onDetachedFromWindow();

Mockito.verify(presenter, Mockito.times(1)).detachView(retainingInstanceState);
}

@Test
public void reuseRetainingPresenter(){
@Test public void reuseRetainingPresenter() {
Mockito.when(callback.getPresenter()).thenReturn(presenter);
delegate.onAttachedToWindow();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void finishActivity(Bundle bundle) {
boolean retaining = true;
Mockito.when(callback.getPresenter()).thenReturn(presenter);
Mockito.when(callback.getViewState()).thenReturn(viewState);
Mockito.when(callback.isRetainInstance()).thenReturn(retaining);
Mockito.when(callback.shouldInstanceBeRetained()).thenReturn(retaining);

Bundle bundle = new Bundle();
finishActivity(bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private void finishFragment(Bundle bundle) {
boolean retaining = false;
Mockito.when(callback.getPresenter()).thenReturn(presenter);
Mockito.when(callback.getViewState()).thenReturn(viewState);
Mockito.when(callback.isRetainInstance()).thenReturn(retaining);
Mockito.when(callback.shouldInstanceBeRetained()).thenReturn(retaining);

Bundle bundle = new Bundle();
finishFragment(bundle);
Expand All @@ -164,7 +164,7 @@ private void finishFragment(Bundle bundle) {
boolean retaining = true;
Mockito.when(callback.getPresenter()).thenReturn(presenter);
Mockito.when(callback.getViewState()).thenReturn(viewState);
Mockito.when(callback.isRetainInstance()).thenReturn(retaining);
Mockito.when(callback.shouldInstanceBeRetained()).thenReturn(retaining);

Bundle bundle = new Bundle();
finishFragment(bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class ViewGroupMvpViewStateDelegateImplTest {
Mockito.verify(presenter, Mockito.times(1)).attachView(view);
Mockito.verify(callback, Mockito.never()).setRestoringViewState(Mockito.anyBoolean());
Mockito.verify(callback, Mockito.times(1)).setViewState(viewState);
Mockito.verify(viewState, Mockito.never()).apply(view, callback.isRetainInstance());
Mockito.verify(viewState, Mockito.never()).apply(view, callback.shouldInstanceBeRetained());
Mockito.verify(callback, Mockito.times(1)).onNewViewStateInstance();
}

Expand All @@ -86,7 +86,7 @@ public class ViewGroupMvpViewStateDelegateImplTest {
Mockito.when(callback.createPresenter()).thenReturn(presenter);
Mockito.when(callback.createViewState()).thenReturn(viewState);
Mockito.when(callback.getViewState()).thenReturn(viewState);
Mockito.when(callback.isRetainInstance()).thenReturn(retaining);
Mockito.when(callback.shouldInstanceBeRetained()).thenReturn(retaining);

Mockito.when(callback.superOnSaveInstanceState()).thenReturn(new Parcelable() {
@Override public int describeContents() {
Expand Down Expand Up @@ -170,7 +170,7 @@ public class ViewGroupMvpViewStateDelegateImplTest {
boolean retaining = true;
Mockito.when(callback.getPresenter()).thenReturn(presenter);
Mockito.when(callback.getViewState()).thenReturn(viewState);
Mockito.when(callback.isRetainInstance()).thenReturn(retaining);
Mockito.when(callback.shouldInstanceBeRetained()).thenReturn(retaining);

delegate.onDetachedFromWindow();

Expand Down

0 comments on commit fa95ee6

Please sign in to comment.