58,454
社区成员
发帖
与我相关
我的任务
分享
public class AddControllerTest extends ControllerTestCase {
@Test
public void run() throws Exception {
tester.param("id","text");
tester.param("password","pass");
tester.start("/user/add");
AddController controller = tester.getController();
assertThat(controller, is(notNullValue()));
assertThat(tester.isRedirect(), is(false));
assertThat(tester.getDestinationPath(), is("/user/add.jsp"));
Account ac = Datastore.query(Account.class).asSingle();
assertThat(ac,is(notNullValue()));
assertThat(ac.getId(),is("test"));
assertThat(ac.getPassword(),is("pass"));
}
}
~~~~~~~~~~~~~~~~~
public class AddController extends Controller {
@Override
public Navigation run() throws Exception {
return forward("add.jsp");
}
}
public void testWhiteSpace() throws Exception {
assertThat(service, is(notNullValue()));
Account ac = new Account();
ac.setId("");
ac.setPassword("password");
boolean b1 = service.save(ac);
assertThat(b1, is(false));
Account ac2 = new Account();
ac2.setId("test");
ac2.setPassword(" ");
boolean b2 = service.save(ac2);
assertThat(b2, is(false));
}