我正在尝试熟悉 TDD 和 Presenter First Pattern。现在我一直在为我的 Presenter.class 编写一个测试用例。我的目标是涵盖整个 Presenter.class,包括动作事件,但我不知道如何使用 Mockito 来完成。
Presenter.class:
public class Presenter {
IModel model;
IView view;
public Presenter(final IModel model, final IView view) {
this.model = model;
this.view = view;
this.model.addModelChangesListener(new AbstractAction() {
public void actionPerformed(ActionEvent arg0) {
view.setText(model.getText());
}
});
}}
IView.class:
public interface IView {
public void setText(String text);
}
模型类:
public interface IModel {
public void setText();
public String getText();
public void whenModelChanges();
public void addModelChangesListener(AbstractAction action);
}
PresenterTest.class:
@RunWith(MockitoJUnitRunner.class)
public class PresenterTest {
@Mock
IView view;
@Mock
IModel model;
@Before
public void setup() {
new Presenter(model, view);
}
@Test
public void test1() {
}
}
提前致谢!