I am using AndroidAnnotations
in my project and I want to test a presenter.
The test suite runs and @Test
methods are apparently called before the injection has finished, because I get NullPointerException
whenever I try to use the `LoginPresenter in my test code.
@RunWith(MockitoJUnitRunner.class)
@EBean
public class LoginPresenterTest {
@Bean
LoginPresenter loginPresenter;
@Mock
private LoginView loginView;
@AfterInject
void initLoginPresenter() {
loginPresenter.setLoginView(loginView);
}
@Test
public void whenUserNameIsEmptyShowErrorOnLoginClicked() throws Exception {
when(loginView.getUserName()).thenReturn("");
when(loginView.getPassword()).thenReturn("asdasd");
loginPresenter.onLoginClicked();
verify(loginView).setEmailFieldErrorMessage();
}
}