2个class如何在test中添加一个id和password为空白时返回的验证。
另外问下这里添加好还是在service中添加好,如果在service中添加如何写。请帮忙,谢谢。
- Java code
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"); } }
------解决方案--------------------
------解决方案--------------------
- Java code
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)); }