当前位置: 代码迷 >> Eclipse >> 生手求指导,help
  详细解决方案

生手求指导,help

热度:39   发布时间:2016-04-23 13:26:07.0
新手求指导,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));      }
  相关解决方案