2

I have a gwtp presenter, in some cases it must add to popupslot another presenter.

How can I verify this fact in test?

I'm using Jukito for tests.

Presenter's code:

...
@Override
public void onAddPersonClick() {
    editPersonPresenter.initForCreating();
    addToPopupSlot(editPersonPresenter);
}
...

Test:

@RunWith(JukitoRunner.class)
public class PersonsPagePresenterTest {

    @Inject
    PersonPagePresenter personPagePresenter;

    @Test
    public void testAddPersonClick() {
        personPagePresenter.onAddPersonClick();
        //how to verify addToPopupSlot(editPersonPresenter);?
    }
}

The problem is that all injected presenters in test are not mocks (only their views are mocks)

durron597
  • 31,968
  • 17
  • 99
  • 158
kosbr
  • 388
  • 2
  • 11

1 Answers1

1

You'll need to spy the instance using mockito since you want to verify that an instance method is called. Notice that I removed the @Inject on the PersonPagePresenter field as it's injected through the setUp method

@RunWith(JukitoRunner.class) 
public class PersonsPagePresenterTest {
    PersonPagePresenter personPagePresenter;

    @Before
    public void setUp(PersonPagePresenter personPagePresenter) {
        this.personPagePresenter = Mockito.spy(personPagePresenter);
    }

    @Test
    public void testAddPersonClick() {
        personPagePresenter.onAddPersonClick();

        Mockito.verify(personPagePresenter).addToPopupSlot(editPersonPresenter);
    } 
}
meriouma
  • 121
  • 5