forked from sockeqwe/mosby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
283 additions
and
112 deletions.
There are no files selected for viewing
78 changes: 0 additions & 78 deletions
78
...va/com/hannesdorfmann/mosby3/mvi/integrationtest/lifecycle/LifecycleTestActivityTest.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...annesdorfmann/mosby3/mvi/integrationtest/lifecycle/activity/MviLifecycleActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2016 Hannes Dorfmann. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.activity; | ||
|
||
import android.content.pm.ActivityInfo; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestPresenter; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) public class MviLifecycleActivityTest { | ||
|
||
@Rule public ActivityTestRule<MviLifecycleActivity> rule = | ||
new ActivityTestRule<>(MviLifecycleActivity.class); | ||
|
||
private static LifecycleTestPresenter presenter; | ||
|
||
@Test public void testConfigChange() throws Exception { | ||
// Context of the app under test. | ||
MviLifecycleActivity portraitActivity = rule.getActivity(); | ||
|
||
presenter = portraitActivity.presenter; | ||
Assert.assertNotNull(presenter); | ||
Assert.assertEquals(1, portraitActivity.createPresenterInvokations); | ||
Assert.assertEquals(1, presenter.attachViewInvokations); | ||
Assert.assertTrue(presenter.attachedView == portraitActivity); | ||
|
||
Thread.sleep(1000); | ||
|
||
// | ||
// Screen orientation change | ||
// | ||
portraitActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | ||
Thread.sleep(1000); | ||
|
||
Assert.assertEquals(1, presenter.detachViewInvokations); | ||
Assert.assertTrue(presenter.onDettachViewRetainInstance); | ||
|
||
Assert.assertEquals(1, MviLifecycleActivity.createPresenterInvokations); | ||
Assert.assertEquals(2, presenter.attachViewInvokations); | ||
Assert.assertTrue(presenter.attachedView != portraitActivity); | ||
} | ||
|
||
@AfterClass public static void checkPresenterNotRetained() { | ||
|
||
// TODO is there a better way to test after onDestroy() has been called? | ||
Assert.assertNotNull(presenter); | ||
Assert.assertEquals(2, presenter.detachViewInvokations); | ||
Assert.assertFalse(presenter.onDettachViewRetainInstance); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...nn/mosby3/mvi/integrationtest/lifecycle/fragment/SimpleFragmentContainerActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2016 Hannes Dorfmann. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.fragment; | ||
|
||
import android.content.pm.ActivityInfo; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestPresenter; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) public class SimpleFragmentContainerActivityTest { | ||
|
||
@Rule public ActivityTestRule<SimpleFragmentContainerActivity> rule = | ||
new ActivityTestRule<>(SimpleFragmentContainerActivity.class); | ||
|
||
private static LifecycleTestPresenter presenter; | ||
|
||
@Test public void testConfigChange() throws Exception { | ||
// Context of the app under test. | ||
SimpleFragmentContainerActivity portraitActivity = rule.getActivity(); | ||
|
||
SimpleMviLifecycleFragment portraitFragment = portraitActivity.getFragment(); | ||
|
||
presenter = portraitFragment.presenter; | ||
Assert.assertNotNull(presenter); | ||
Assert.assertEquals(1, SimpleMviLifecycleFragment.createPresenterInvokations); | ||
Assert.assertEquals(1, presenter.attachViewInvokations); | ||
Assert.assertTrue(presenter.attachedView == portraitFragment); | ||
|
||
Thread.sleep(1000); | ||
|
||
// | ||
// Screen orientation change | ||
// | ||
portraitActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | ||
Thread.sleep(1000); | ||
|
||
Assert.assertEquals(1, presenter.detachViewInvokations); | ||
Assert.assertTrue(presenter.onDettachViewRetainInstance); | ||
|
||
SimpleFragmentContainerActivity landscapeActivity = | ||
rule.getActivity(); // TODO this one returnes always the same activity instance. No difference between landscape / portrait instance | ||
|
||
SimpleMviLifecycleFragment landscapeFragment = landscapeActivity.getFragment(); | ||
Assert.assertEquals(1, SimpleMviLifecycleFragment.createPresenterInvokations); | ||
Assert.assertEquals(2, presenter.attachViewInvokations); | ||
Assert.assertTrue(presenter.attachedView != portraitFragment); | ||
} | ||
|
||
@AfterClass | ||
public static void checkPresenterNotRetained(){ | ||
|
||
// TODO is there a better way to test after onDestroy() has been called? | ||
Assert.assertNotNull(presenter); | ||
Assert.assertEquals(2, presenter.detachViewInvokations); | ||
Assert.assertFalse(presenter.onDettachViewRetainInstance); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
...ion-test/src/main/java/com/hannesdorfmann/mosby3/mvi/integrationtest/MviTestActivity.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...rfmann/mosby3/mvi/integrationtest/lifecycle/fragment/SimpleFragmentContainerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2016 Hannes Dorfmann. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.fragment; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.R; | ||
|
||
/** | ||
* @author Hannes Dorfmann | ||
*/ | ||
public class SimpleFragmentContainerActivity extends AppCompatActivity { | ||
|
||
private static final String TAG = "Test-Fragment"; | ||
|
||
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_lifecycle); | ||
|
||
if (savedInstanceState == null) { | ||
SimpleMviLifecycleFragment f = new SimpleMviLifecycleFragment(); | ||
getSupportFragmentManager().beginTransaction().replace(R.id.container, f, TAG).commitNow(); | ||
} | ||
} | ||
|
||
public SimpleMviLifecycleFragment getFragment(){ | ||
return (SimpleMviLifecycleFragment) getSupportFragmentManager().findFragmentByTag(TAG); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...nesdorfmann/mosby3/mvi/integrationtest/lifecycle/fragment/SimpleMviLifecycleFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2016 Hannes Dorfmann. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.fragment; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import com.hannesdorfmann.mosby3.mvi.MviFragment; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.R; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestPresenter; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestView; | ||
|
||
/** | ||
* @author Hannes Dorfmann | ||
*/ | ||
public class SimpleMviLifecycleFragment extends MviFragment<LifecycleTestView, LifecycleTestPresenter> implements LifecycleTestView { | ||
|
||
|
||
public LifecycleTestPresenter presenter; | ||
public static int createPresenterInvokations = 0; | ||
|
||
@NonNull @Override public LifecycleTestPresenter createPresenter() { | ||
createPresenterInvokations++; | ||
presenter = new LifecycleTestPresenter(); | ||
return presenter; | ||
} | ||
|
||
@Nullable @Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, | ||
@Nullable Bundle savedInstanceState) { | ||
return inflater.inflate(R.layout.fragment_mvi, container, false); | ||
} | ||
} |
Oops, something went wrong.