Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
Remove more changing configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
StefMa committed Jul 11, 2017
1 parent a5ac1c9 commit 109e5eb
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public class HostingActivity {

private final Activity mActivityMock;

private boolean mIsChangingConfiguration;

private boolean mIsFinishing;

public HostingActivity() {
Expand All @@ -50,10 +48,6 @@ public boolean isFinishing() {
return mIsFinishing;
}

public void setChangingConfiguration(final boolean changingConfiguration) {
mIsChangingConfiguration = changingConfiguration;
}

public void setFinishing(final boolean finishing) {
mIsFinishing = finishing;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ public void activityChangingConfiguration_retainFalse_backstackFalse() {
assertThat(fragment.getPresenter().isDestroyed()).isTrue();
assertThat(mSavior.getPresenterCount()).isEqualTo(0);

// When the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);

// Then nothing happens with the fragment, not managed anymore
assertThat(fragment.getPresenter().isDestroyed()).isTrue();
assertThat(mSavior.getPresenterCount()).isEqualTo(0);
Expand Down Expand Up @@ -103,7 +100,6 @@ public void activityChangingConfiguration_retainFalse_backstackTrue() {
assertThat(mSavior.getPresenterCount()).isEqualTo(0);

// When the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);
fragment.onSaveInstanceState(mFragmentSavedState);
fragment.onDestroy();

Expand Down Expand Up @@ -150,7 +146,6 @@ public void activityChangingConfiguration_retainTrue_backstackFalse() {
assertThat(mSavior.getPresenterCount()).isEqualTo(0);

// When the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);

// Then nothing happens with the fragment, not managed anymore
assertThat(fragment.getPresenter().isDestroyed()).isTrue();
Expand Down Expand Up @@ -195,7 +190,6 @@ public void activityChangingConfiguration_retainTrue_backstackTrue() {
assertThat(mSavior.getPresenterCount()).isEqualTo(1);

// When the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
hostingActivity.getMockActivityInstance(), mActivitySavedState);
fragment.onSaveInstanceState(mFragmentSavedState);
Expand Down Expand Up @@ -270,7 +264,6 @@ public void activityChangingConfiguration_thenFinish_retainFalse_backstackTrue()
assertThat(mSavior.getPresenterCount()).isEqualTo(0);

// When the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);
assertThat(mSavior.mActivityInstanceObserver).isNull();
fragment.onSaveInstanceState(mFragmentSavedState);
fragment.onDestroy();
Expand Down Expand Up @@ -330,7 +323,6 @@ public void activityChangingConfiguration_thenFinish_retainTrue_backstackTrue()
assertThat(mSavior.getPresenterCount()).isEqualTo(1);

// When the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
hostingActivity.getMockActivityInstance(), mActivitySavedState);
fragment.onSaveInstanceState(mFragmentSavedState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public void activityChangingConfiguration_retainFalse_backstackTrue_dkATrue() {
fragment.onDestroyView();

// And when the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);
fragment.onSaveInstanceState(mFragmentSavedState);
fragment.onDestroy();

Expand Down Expand Up @@ -140,7 +139,6 @@ public void activityChangingConfiguration_retainTrue_backstackFalse_dkATrue() {
assertThat(mSavior.getPresenterCount()).isEqualTo(0);

// When the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);

// Then nothing happens with the fragment, not managed anymore
assertThat(fragment.getPresenter().isDestroyed()).isTrue();
Expand Down Expand Up @@ -182,7 +180,6 @@ public void activityChangingConfiguration_retainTrue_backstackTrue_dkATrue() {
assertThat(mSavior.getPresenterCount()).isEqualTo(1);

// When the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
hostingActivity.getMockActivityInstance(), mActivitySavedState);
fragment.onSaveInstanceState(mFragmentSavedState);
Expand Down Expand Up @@ -221,13 +218,13 @@ public void activityChangingConfiguration_retainTrue_backstackTrue_dkATrue() {
}

@Test
public void activityChangingConfiguration_thenFinish_retainTrue_backstackTrue_dkATrue() {
public void activityChangingConfiguration_thenFinish_retainFalse_backstackTrue_dkATrue() {

final HostingActivity hostingActivity = new HostingActivity();

// Given a Presenter that uses a static savior to retain itself.
final TestPresenter presenter = new TestPresenter(new TiConfiguration.Builder()
.setRetainPresenterEnabled(true)
.setRetainPresenterEnabled(false)
.build());

// And given a Fragment.
Expand All @@ -250,45 +247,41 @@ public void activityChangingConfiguration_thenFinish_retainTrue_backstackTrue_dk
fragment.onStop();
fragment.onDestroyView();

// Then the presenter is not destroyed and saved in the savior
// Then the presenter is not destroyed, onDestroy wasn't called
assertThat(fragment.getPresenter().isDestroyed()).isFalse();
assertThat(mSavior.getPresenterCount()).isEqualTo(1);

// When the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
hostingActivity.getMockActivityInstance(), mActivitySavedState);
// Then the presenter is not saved in the savior
assertThat(mSavior.getPresenterCount()).isEqualTo(0);

assertThat(mSavior.mActivityInstanceObserver).isNull();
fragment.onSaveInstanceState(mFragmentSavedState);
fragment.onDestroy();

// Then the Presenter is destroyed and not saved in the savior.
assertThat(fragment.getPresenter().isDestroyed()).isTrue();
assertThat(mSavior.getPresenterCount()).isEqualTo(0);

// Then a new Activity is recreated.
final HostingActivity hostingActivity2 = new HostingActivity();
mSavior.mActivityInstanceObserver.onActivityCreated(
hostingActivity2.getMockActivityInstance(), mActivitySavedState);

// Then the Presenter is not destroyed and saved in the savior.
assertThat(fragment.getPresenter().isDestroyed()).isFalse();
assertThat(mSavior.getPresenterCount()).isEqualTo(1);
assertThat(mSavior.mActivityInstanceObserver).isNull();

// When the Activity gets finished
hostingActivity2.setFinishing(true);
mSavior.mActivityInstanceObserver.onActivityDestroyed(
hostingActivity2.getMockActivityInstance());
assertThat(mSavior.mActivityInstanceObserver).isNull();

// Then the same presenter is destroyed
// Then nothing happens, the presenter is already destroyed
assertThat(mSavior.getPresenterCount()).isEqualTo(0);
assertThat(presenter.isDestroyed()).isTrue();
}


@Test
public void activityChangingConfiguration_thenFinish_retainFalse_backstackTrue_dkATrue() {
public void activityChangingConfiguration_thenFinish_retainTrue_backstackTrue_dkATrue() {

final HostingActivity hostingActivity = new HostingActivity();

// Given a Presenter that uses a static savior to retain itself.
final TestPresenter presenter = new TestPresenter(new TiConfiguration.Builder()
.setRetainPresenterEnabled(false)
.setRetainPresenterEnabled(true)
.build());

// And given a Fragment.
Expand All @@ -311,31 +304,30 @@ public void activityChangingConfiguration_thenFinish_retainFalse_backstackTrue_d
fragment.onStop();
fragment.onDestroyView();

// Then the presenter is not destroyed, onDestroy wasn't called
// Then the presenter is not destroyed and saved in the savior
assertThat(fragment.getPresenter().isDestroyed()).isFalse();
assertThat(mSavior.getPresenterCount()).isEqualTo(1);

// Then the presenter is not saved in the savior
assertThat(mSavior.getPresenterCount()).isEqualTo(0);

// When the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);
assertThat(mSavior.mActivityInstanceObserver).isNull();
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
hostingActivity.getMockActivityInstance(), mActivitySavedState);
fragment.onSaveInstanceState(mFragmentSavedState);
fragment.onDestroy();

// Then the Presenter is destroyed and not saved in the savior.
assertThat(fragment.getPresenter().isDestroyed()).isTrue();
assertThat(mSavior.getPresenterCount()).isEqualTo(0);

// Then a new Activity is recreated.
final HostingActivity hostingActivity2 = new HostingActivity();
assertThat(mSavior.mActivityInstanceObserver).isNull();
mSavior.mActivityInstanceObserver.onActivityCreated(
hostingActivity2.getMockActivityInstance(), mActivitySavedState);

// Then the Presenter is not destroyed and saved in the savior.
assertThat(fragment.getPresenter().isDestroyed()).isFalse();
assertThat(mSavior.getPresenterCount()).isEqualTo(1);

// When the Activity gets finished
hostingActivity2.setFinishing(true);
assertThat(mSavior.mActivityInstanceObserver).isNull();
mSavior.mActivityInstanceObserver.onActivityDestroyed(
hostingActivity2.getMockActivityInstance());

// Then nothing happens, the presenter is already destroyed
// Then the same presenter is destroyed
assertThat(mSavior.getPresenterCount()).isEqualTo(0);
assertThat(presenter.isDestroyed()).isTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ public void ignoreWhenActivityChangesConfiguration() throws Exception {
assertThat(savior.getPresenterCount()).isEqualTo(1);
assertThat(id).isNotEmpty().isNotNull();

hostingActivity.setChangingConfiguration(true);
savior.mActivityInstanceObserver
.onActivityDestroyed(hostingActivity.getMockActivityInstance());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void activityChangingConfiguration_retainFalse() {
assertThat(mSavior.mActivityInstanceObserver).isNull();

// And when the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);
fragment.onSaveInstanceState(mFragmentSavedState);
fragment.onStop();
fragment.onDestroyView();
Expand Down Expand Up @@ -131,7 +130,6 @@ public void activityChangingConfiguration_retainTrue() {
assertThat(mSavior.getPresenterCount()).isEqualTo(1);

// And when the Activity is changing its configurations.
hostingActivity.setChangingConfiguration(true);
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
hostingActivity.getMockActivityInstance(), mActivitySavedState);
fragment.onSaveInstanceState(mFragmentSavedState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public void activityChangingConfiguration_retainFalse_dkATrue() {
assertThat(mSavior.mActivityInstanceObserver).isNull();

// And when the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);
fragment.onSaveInstanceState(mFragmentSavedState);
fragment.onStop();
fragment.onDestroyView();
Expand Down Expand Up @@ -131,7 +130,6 @@ public void activityChangingConfiguration_retainTrue_dkATrue() {
assertThat(mSavior.getPresenterCount()).isEqualTo(1);

// And when the Activity is changing its configuration.
hostingActivity.setChangingConfiguration(true);
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
hostingActivity.getMockActivityInstance(), mActivitySavedState);
fragment.onSaveInstanceState(mFragmentSavedState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ public TiView provideView() {
return mock(TiView.class);
}

public void setChangingConfiguration(final boolean changingConfiguration) {
mHostingActivity.setChangingConfiguration(changingConfiguration);
}

public void setFinishing(final boolean finishing) {
mHostingActivity.setFinishing(finishing);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public void configurationChange_retainFalse_dkAFalse() throws Exception {

// When the Activity changes configurations
activity.setFinishing(false);
activity.setChangingConfiguration(true);
activity.onStop();
assertThat(mSavior.mActivityInstanceObserver).isNull();
activity.onSaveInstanceState(mActivitySavedState);
Expand Down Expand Up @@ -98,7 +97,6 @@ public void configurationChange_retainFalse_dkATrue() throws Exception {

// When the Activity changes configurations
activity.setFinishing(false);
activity.setChangingConfiguration(true);
activity.onStop();
assertThat(mSavior.mActivityInstanceObserver).isNull();
activity.onSaveInstanceState(mActivitySavedState);
Expand Down Expand Up @@ -149,7 +147,6 @@ public void configurationChange_retainTrue_dkAFalse() throws Exception {

// When the Activity changes configurations
activity.setFinishing(false);
activity.setChangingConfiguration(true);
activity.onStop();
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
activity.getMockActivityInstance(), mActivitySavedState);
Expand Down Expand Up @@ -198,7 +195,6 @@ public void configurationChange_retainTrue_dkATrue() throws Exception {

// When the Activity changes configurations
activity.setFinishing(false);
activity.setChangingConfiguration(true);
activity.onStop();
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
activity.getMockActivityInstance(), mActivitySavedState);
Expand Down Expand Up @@ -247,7 +243,6 @@ public void finish_retainFalse_dkAFalse() throws Exception {

// When the Activity gets finished
activity.setFinishing(true);
activity.setChangingConfiguration(false);
activity.onStop();
assertThat(mSavior.mActivityInstanceObserver).isNull();
activity.onSaveInstanceState(mActivitySavedState);
Expand Down Expand Up @@ -281,7 +276,6 @@ public void finish_retainFalse_dkATrue() throws Exception {

// When the Activity gets finished
activity.setFinishing(true);
activity.setChangingConfiguration(false);
activity.onStop();
assertThat(mSavior.mActivityInstanceObserver).isNull();
activity.onSaveInstanceState(mActivitySavedState);
Expand Down Expand Up @@ -318,7 +312,6 @@ public void finish_retainTrue_dkAFalse() throws Exception {

// When the Activity gets finished
activity.setFinishing(true);
activity.setChangingConfiguration(false);
activity.onStop();
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
activity.getMockActivityInstance(), mActivitySavedState);
Expand Down Expand Up @@ -353,7 +346,6 @@ public void finish_retainTrue_dkATrue() throws Exception {

// When the Activity gets finished
activity.setFinishing(true);
activity.setChangingConfiguration(false);
activity.onStop();
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
activity.getMockActivityInstance(), mActivitySavedState);
Expand Down Expand Up @@ -388,7 +380,6 @@ public void moveToBackground_moveToForeground_retainFalse_dkAFalse() throws Exce

// When the Activity moves to background
activity.setFinishing(false);
activity.setChangingConfiguration(false);
activity.onStop();
assertThat(mSavior.mActivityInstanceObserver).isNull();

Expand Down Expand Up @@ -423,7 +414,6 @@ public void moveToBackground_moveToForeground_retainFalse_dkATrue() throws Excep

// When the Activity moves to background
activity.setFinishing(false);
activity.setChangingConfiguration(false);
activity.onStop();
assertThat(mSavior.mActivityInstanceObserver).isNull();
activity.onSaveInstanceState(mActivitySavedState);
Expand Down Expand Up @@ -475,7 +465,6 @@ public void moveToBackground_moveToForeground_retainTrue_dkAFalse() throws Excep

// When the Activity moves to background
activity.setFinishing(false);
activity.setChangingConfiguration(false);
activity.onStop();
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
activity.getMockActivityInstance(), mActivitySavedState);
Expand Down Expand Up @@ -511,7 +500,6 @@ public void moveToBackground_moveToForeground_retainTrue_dkATrue() throws Except

// When the Activity moves to background
activity.setFinishing(false);
activity.setChangingConfiguration(false);
activity.onStop();
mSavior.mActivityInstanceObserver.onActivitySaveInstanceState(
activity.getMockActivityInstance(), mActivitySavedState);
Expand Down

0 comments on commit 109e5eb

Please sign in to comment.