首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

生手求指导,help

2012-06-24 
新手求指导,help!2个class如何在test中添加一个id和password为空白时返回的验证。另外问下这里添加好还是

新手求指导,help!
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");    }        }


[解决办法]
探讨
看不太懂LZ的test是什么
总之判断为空的方法是:
String password;
String id;
if("".equals(password.trim()) || "".equals(id.trim())){

}

[解决办法]
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));      } 

热点排行