package com.lenguyenthanh.nimble;

import android.os.Bundle;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

public class NimblePresenterTest {
  @Mock
  NimbleView view;
  @Mock
  NimbleView anotherView;

  BasePresenter<NimbleView> presenter;

  @Before
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    presenter = new TestPresenter();
  }

  @Test
  public void takeView_normal_work() throws Exception {
    presenter.takeView(view);
    assertThat(presenter.hasView()).isTrue();
    assertThat(view).isEqualTo(presenter.getView());
  }

  @Test
  public void takeView_addMultipleViews_work() throws Exception {
    presenter = spy(presenter);
    presenter.takeView(view);
    presenter.takeView(anotherView);
    assertThat(presenter.hasView()).isTrue();
    assertThat(anotherView).isEqualTo(presenter.getView());
    verify(presenter).dropView(view);
  }

  @Test
  public void takeView_addMultipleSameViews_work() throws Exception {
    presenter.takeView(view);
    presenter.takeView(view);
    assertThat(presenter.hasView()).isTrue();
    assertThat(view).isEqualTo(presenter.getView());
  }

  @Test
  public void takeView_addNullView_work() throws Exception {
    presenter.takeView(view);
    presenter.takeView(null);
    assertThat(presenter.hasView()).isFalse();
    assertThat(view).isNotEqualTo(presenter.getView());
  }

  @Test
  public void takeView_null_work() throws Exception {
    presenter.takeView(null);
    assertThat(presenter.hasView()).isFalse();
  }

  @Test
  public void dropView_normal_work() throws Exception {
    presenter.takeView(view);
    presenter.dropView(view);
    assertThat(presenter.hasView()).isFalse();
    assertThat(presenter.getView()).isNull();
  }

  public static class TestPresenter extends BasePresenter<NimbleView> {

    @Override
    public void onCreate(Bundle savedInstanceState) {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void onSave(Bundle outState) {

    }
  }
}

@@ -223,16 +223,57 @@
 rtThat;%0A
+import static org.mockito.Mockito.never;%0A
 import s
@@ -303,16 +303,16 @@
 to.spy;%0A
-
 import s
@@ -1206,32 +1206,64 @@
 ows Exception %7B%0A
+    presenter = spy(presenter);%0A
     presenter.ta
@@ -1397,32 +1397,79 @@
 ter.getView());%0A
+    verify(presenter, never()).dropView(view);%0A
   %7D%0A%0A  @Test%0A  p
@@ -1518,32 +1518,64 @@
 ows Exception %7B%0A
+    presenter = spy(presenter);%0A
     presenter.ta
@@ -1713,32 +1713,70 @@
 ter.getView());%0A
+    verify(presenter).dropView(view);%0A
   %7D%0A%0A  @Test%0A  p
@@ -2071,32 +2071,32 @@
 w()).isFalse();%0A
-
     assertThat(p
@@ -2130,16 +2130,258 @@
 );%0A  %7D%0A%0A
+  @Test%0A  public void dropView_differentView_work() throws Exception %7B%0A    presenter.takeView(view);%0A    presenter.dropView(anotherView);%0A    assertThat(presenter.hasView()).isTrue();%0A    assertThat(presenter.getView()).isEqualTo(view);%0A  %7D%0A%0A
   public

Add more test for presenter