示例#1
0
  @Test
  public void testNumericValidator() {
    deleteAndPopulateTable("accounts");
    Account a = new Account();
    // try straight number
    a.set("amount", 1.2);
    a.validate();
    a(a.errors().size()).shouldBeEqual(0);

    // try not number
    a.set("amount", "hello");
    a.validate();
    a(a.errors().size()).shouldBeEqual(1);
    a(a.errors().get("amount")).shouldBeEqual("value is not a number");

    // try numeric string
    a.set("amount", "123");
    a.validate();
    a(a.errors().size()).shouldBeEqual(0);

    // try bad string with a number in it
    a.set("amount", "111 aaa");
    a.validate();
    a(a.errors().size()).shouldBeEqual(1);

    //        //try null value with a validator.
    //        a.set("amount", null);
    //        a.validate();
    //        a(a.errors().size()).shouldBeEqual(1);
    //        a(a.errors().get("amount")).shouldBeEqual("value is not a number");

  }
示例#2
0
  @Test
  public void shouldNotOverwritePreviousValidation() {
    deleteAndPopulateTable("accounts");

    // first validator
    Account account = new Account();
    account.set("amount", "");
    account.validate();
    a(account.errors().get("amount")).shouldEqual("value is missing");

    // second validator
    account.set("amount", "hello");
    account.validate();
    a(account.errors().get("amount")).shouldEqual("value is not a number");
  }