浏览代码

Merge branch 'develop' of https://github.com/swict/LifePlusAndroid into develop

Hasemi 7 年之前
父节点
当前提交
592b3781ff

+ 9 - 17
app/src/main/java/kr/co/zumo/app/lifeplus/view/CheckBoxAllDriver.java

@@ -3,7 +3,7 @@
  */
 package kr.co.zumo.app.lifeplus.view;
 
-import android.widget.CheckBox;
+import android.widget.Checkable;
 
 import java.util.ArrayList;
 
@@ -19,10 +19,10 @@ import java.util.ArrayList;
  */
 public class CheckBoxAllDriver {
 
-  CheckBox allBox;
-  ArrayList<CheckBox> boxes;
+  Checkable allBox;
+  ArrayList<Checkable> boxes;
 
-  public CheckBoxAllDriver(CheckBox allBox) {
+  public CheckBoxAllDriver(Checkable allBox) {
     this.allBox = allBox;
     boxes = new ArrayList<>();
   }
@@ -32,7 +32,7 @@ public class CheckBoxAllDriver {
    *
    * @param box
    */
-  public void addChildBox(CheckBox box) {
+  public void addChildBox(Checkable box) {
     boxes.add(box);
   }
 
@@ -42,11 +42,8 @@ public class CheckBoxAllDriver {
    * @param isChecked true|false
    */
   private void checkAll(boolean isChecked) {
-    CheckBox checkBox;
-    int len = boxes.size();
-    for (int i = 0; i < len; ++i) {
-      checkBox = boxes.get(i);
-      checkBox.setChecked(isChecked);
+    for (Checkable box : boxes) {
+      box.setChecked(isChecked);
     }
   }
 
@@ -54,12 +51,9 @@ public class CheckBoxAllDriver {
    * 모든 버튼이 체크되어있다면 올박스를 체크한다.
    */
   private void applyCheckAll() {
-    CheckBox checkBox;
     boolean isCheckedAll = true;
-    int len = boxes.size();
-    for (int i = 0; i < len; ++i) {
-      checkBox = boxes.get(i);
-      isCheckedAll = isCheckedAll & checkBox.isChecked();
+    for (Checkable box : boxes) {
+      isCheckedAll = isCheckedAll & box.isChecked();
     }
 
     allBox.setChecked(isCheckedAll);
@@ -78,8 +72,6 @@ public class CheckBoxAllDriver {
    */
   public void applyCheckAll(boolean isChecked) {
     checkAll(isChecked);
-
-    applyCheckAll();
   }
 
 }

+ 102 - 0
app/src/test/java/kr/co/zumo/app/lifeplus/view/CheckBoxAllDriverTest.java

@@ -0,0 +1,102 @@
+package kr.co.zumo.app.lifeplus.view;
+
+import android.widget.Checkable;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.powermock.api.mockito.PowerMockito.mock;
+
+/**
+ * CheckBoxAllDriverTest
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2018. 9. 19.]   [최초 작성]
+ * @since 2018. 9. 19.
+ */
+public class CheckBoxAllDriverTest {
+
+  @InjectMocks
+  CheckBoxAllDriver driver;
+
+  @Mock
+  Checkable allBox;
+
+  @Before
+  public void setup() throws Exception {
+    MockitoAnnotations.initMocks(this);
+  }
+
+  @Test
+  public void addChildBox() {
+    TestCheckBox box = spy(TestCheckBox.class);
+    driver.addChildBox(box);
+    driver.check();
+
+    verify(box, times(1)).isChecked();
+  }
+
+  @Test
+  public void check() {
+    TestCheckBox box = spy(TestCheckBox.class);
+    driver.addChildBox(box);
+    driver.addChildBox(box);
+    driver.addChildBox(box);
+    driver.addChildBox(box);
+    driver.addChildBox(box);
+    driver.check();
+
+    verify(box, times(5)).isChecked();
+
+    verify(allBox).setChecked(eq(false));
+
+    box.setChecked(true);
+    driver.check();
+
+    verify(allBox).setChecked(eq(true));
+
+  }
+
+  @Test
+  public void applyCheckAll() {
+
+    Checkable box = mock(Checkable.class);
+    driver.addChildBox(box);
+    driver.addChildBox(box);
+    driver.addChildBox(box);
+    driver.addChildBox(box);
+    driver.addChildBox(box);
+    driver.applyCheckAll(true);
+
+    verify(box, times(5)).setChecked(eq(true));
+  }
+
+  static class TestCheckBox implements Checkable {
+    boolean isChecked = false;
+
+    @Override
+    public void setChecked(boolean checked) {
+      isChecked = checked;
+    }
+
+    @Override
+    public boolean isChecked() {
+      return isChecked;
+    }
+
+    @Override
+    public void toggle() {
+      isChecked = !isChecked;
+    }
+  }
+}

+ 4 - 4
app/src/test/java/kr/co/zumo/app/lifeplus/view/presenter/PresenterTest.java

@@ -15,8 +15,8 @@ public class PresenterTest {
   public void onEvent() {
     Presenter model = spy(new MainPresenter(mock(ScreenChanger.class), mock(IMainView.class)));
 
-    model.onEvent(Event.BACK);
-    verify(model).onEvent(eq(Event.BACK), eq(Presenter.INT_NONE), eq(Presenter.STRING_NONE));
+    model.onEvent(Event.LOGIN);
+    verify(model).performOnEvent(eq(Event.LOGIN), eq(Presenter.INT_NONE), eq(Presenter.STRING_NONE));
   }
 
   @Test
@@ -25,7 +25,7 @@ public class PresenterTest {
     Presenter model = spy(new MainPresenter(mock(ScreenChanger.class), mock(IMainView.class)));
 
     model.onEvent(Event.CLICK, 1234);
-    verify(model).onEvent(eq(Event.CLICK), eq(1234), eq(Presenter.STRING_NONE));
+    verify(model).performOnEvent(eq(Event.CLICK), eq(1234), eq(Presenter.STRING_NONE));
   }
 
   @Test
@@ -33,6 +33,6 @@ public class PresenterTest {
     Presenter model = spy(new MainPresenter(mock(ScreenChanger.class), mock(IMainView.class)));
 
     model.onEvent(Event.LOGIN, "hello");
-    verify(model).onEvent(eq(Event.LOGIN), eq(Presenter.INT_NONE), eq("hello"));
+    verify(model).performOnEvent(eq(Event.LOGIN), eq(Presenter.INT_NONE), eq("hello"));
   }
 }