新手求指导,help!

mkworld 2012-06-16 11:06:12
2个class如何在test中添加一个id和password为空白时返回的验证。
另外问下这里添加好还是在service中添加好,如果在service中添加如何写。请帮忙,谢谢。

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");
}


}


...全文
78 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
psp_66 2012-06-23
  • 打赏
  • 举报
回复

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));
}
mkworld 2012-06-17
  • 打赏
  • 举报
回复
耐心等待,继续教!
子曰花开 2012-06-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
看不太懂LZ的test是什么
总之判断为空的方法是:
String password;
String id;
if("".equals(password.trim()) || "".equals(id.trim())){

}
[/Quote]
test应该是数据库名吧!
brightyq 2012-06-17
  • 打赏
  • 举报
回复
看不太懂LZ的test是什么
总之判断为空的方法是:
String password;
String id;
if("".equals(password.trim()) || "".equals(id.trim())){

}

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧