|
|
@@ -13,6 +13,7 @@ import kr.co.zumo.app.lifeplus.model.LifeplusPreferences;
|
|
|
import kr.co.zumo.app.lifeplus.model.SuperModel;
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
+import static org.junit.Assert.assertFalse;
|
|
|
import static org.mockito.ArgumentMatchers.argThat;
|
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
|
import static org.powermock.api.mockito.PowerMockito.doReturn;
|
|
|
@@ -31,11 +32,12 @@ import static org.powermock.api.mockito.PowerMockito.verifyPrivate;
|
|
|
* @since 2018. 10. 12.
|
|
|
*/
|
|
|
@RunWith(PowerMockRunner.class)
|
|
|
-@PrepareForTest(ActivityStarter.class)
|
|
|
+@PrepareForTest(ActivityStarter.class) // PowerMock 테스트를 위해서 필요
|
|
|
public class ActivityStarterTest {
|
|
|
- LifeplusPreferences lifeplusPreferences;
|
|
|
- Context context;
|
|
|
- ActivityStarter starter;
|
|
|
+
|
|
|
+ private LifeplusPreferences lifeplusPreferences;
|
|
|
+ private Context context;
|
|
|
+ private ActivityStarter starter;
|
|
|
|
|
|
@Before
|
|
|
public void setup() {
|
|
|
@@ -56,11 +58,7 @@ public class ActivityStarterTest {
|
|
|
|
|
|
starter.launch(false);
|
|
|
|
|
|
- /**
|
|
|
- * 프라이빗 메서드 테스트
|
|
|
- *
|
|
|
- * 클래스 비교 테스트
|
|
|
- */
|
|
|
+ // 네트워크 에러 액티비티로 이동;
|
|
|
verifyPrivate(starter).invoke("gotoScreen", argThat(new ClassOrSubclassMatcher<>(NetworkErrorActivity.class)));
|
|
|
}
|
|
|
|
|
|
@@ -73,13 +71,16 @@ public class ActivityStarterTest {
|
|
|
|
|
|
starter.launch(true);
|
|
|
|
|
|
- assertEquals(false, SuperModel.getInstance().isActiveMember());
|
|
|
+ // 토큰이 없기 때문에, 아직 비활성 멤버
|
|
|
+ assertFalse(SuperModel.getInstance().isActiveMember());
|
|
|
+ // 유저 아이디 확인
|
|
|
assertEquals("dummy", SuperModel.getInstance().getUserId());
|
|
|
+ // login("dummy") 실행
|
|
|
verifyPrivate(starter).invoke("login", eq("dummy"));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void launch3() {
|
|
|
+ public void launch3() throws Exception {
|
|
|
// 권한 안내
|
|
|
doReturn(false).when(lifeplusPreferences).isPermissionInfoDone();
|
|
|
doReturn(true).when(lifeplusPreferences).isTutorialDone();
|
|
|
@@ -87,15 +88,11 @@ public class ActivityStarterTest {
|
|
|
|
|
|
starter.launch(true);
|
|
|
|
|
|
- try {
|
|
|
- verifyPrivate(starter).invoke("gotoScreen", argThat(new ClassOrSubclassMatcher<>(PermissionInfoActivity.class)));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ verifyPrivate(starter).invoke("gotoScreen", argThat(new ClassOrSubclassMatcher<>(PermissionInfoActivity.class)));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void launch4() {
|
|
|
+ public void launch4() throws Exception {
|
|
|
// 온보딩
|
|
|
doReturn(true).when(lifeplusPreferences).isPermissionInfoDone();
|
|
|
doReturn(false).when(lifeplusPreferences).isTutorialDone();
|
|
|
@@ -103,15 +100,11 @@ public class ActivityStarterTest {
|
|
|
|
|
|
starter.launch(true);
|
|
|
|
|
|
- try {
|
|
|
- verifyPrivate(starter).invoke("gotoScreen", argThat(new ClassOrSubclassMatcher<>(OnBoardingActivity.class)));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ verifyPrivate(starter).invoke("gotoScreen", argThat(new ClassOrSubclassMatcher<>(OnBoardingActivity.class)));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void launch5() {
|
|
|
+ public void launch5() throws Exception {
|
|
|
// 비회원
|
|
|
doReturn(true).when(lifeplusPreferences).isPermissionInfoDone();
|
|
|
doReturn(true).when(lifeplusPreferences).isTutorialDone();
|
|
|
@@ -119,13 +112,10 @@ public class ActivityStarterTest {
|
|
|
|
|
|
starter.launch(true);
|
|
|
|
|
|
- assertEquals(false, SuperModel.getInstance().isActiveMember());
|
|
|
+ // 토큰, 아이디 가 없기 때문에 비활성 멤버
|
|
|
+ assertFalse(SuperModel.getInstance().isActiveMember());
|
|
|
|
|
|
- try {
|
|
|
- verifyPrivate(starter).invoke("gotoScreen", argThat(new ClassOrSubclassMatcher<>(MainActivity.class)));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ verifyPrivate(starter).invoke("gotoScreen", argThat(new ClassOrSubclassMatcher<>(MainActivity.class)));
|
|
|
}
|
|
|
|
|
|
public class ClassOrSubclassMatcher<T> implements ArgumentMatcher<Class<T>> {
|
|
|
@@ -138,7 +128,6 @@ public class ActivityStarterTest {
|
|
|
|
|
|
@Override
|
|
|
public boolean matches(Class argument) {
|
|
|
- System.out.print(argument.getSimpleName());
|
|
|
if (null != argument) {
|
|
|
return argument.equals(targetClass);
|
|
|
}
|