次の Struts アクションがあります。
public ActionForward addSomething(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
SomeForm sForm = (SomeForm) form;
Test t = testForm.toTest();
if (tDao.checkExistsTest(t.getTest())) {
return mapping.findForward("failure");
} else {
t.setType(new TestType(tess));
t.setPassword(testForm.getPassword());
tDao.add(t);
return mapping.findForward("success");
}
}
testAddSomethingSuccessメソッドをテストするために、次のコードを実行しました。
@Test
public void testAddSomethingSuccess() throws Exception {
form.setTest("LOL");
form.setTestName("lol");
form.setPassword("12345");
ActionForward forward = action.addSomething(mapping, form, request, response);
assertEquals(tDao.getList().get(0).getTest(), "LOL");
assertEquals(tDao.getList().get(0).getTestName(), "lol");
assertEquals(tDao.getList().get(0).getPassword(), "12345");
assertEquals("success", forward.getName());
}
どのようにtestAddClientFailed()を実装できますか??? :
@Test
public void testAddSomethingFailed() throws Exception {
form.setTestName("lol");
t.checkIfExists("lol");
ActionForward forward = action.addSomething(mapping, form, request, response);
assertEquals("failure", forward.getName());
}