我有一个简单的控制器,我想为其编写一个 Mockito 单元测试。这是代码:
private final UserController userCtl;
public String get(final Model model) {
return this.userCtl.getLoginForm(model);
}
这是我的测试:
@Mock
private Model model;
private DefaultControllerImpl sut;
@Before
public void setup() {
this.ctl = new DefaultControllerImpl(this.userCtl, this.authService, this.orgService, this.riskSpaceService);
this.ctl.setMessageSource(this.messageSource);
}
@Test
public void testGet() {
final String view = this.sut.get(this.model);
assertThat(view).isEqualTo(UserController.LOGIN_PATH);
}
但是,此测试始终返回 null。我怎样才能为这个控制器编写一个合适的单元测试?