Example #1
0
  @Test
  public void withMinLengthAndFilter() throws Exception {
    sut.minLength(5);
    List<Representant<String>> all = sut.getRepresentatives(null);
    assertEquals(7, all.size());
    assertThat(all, hasItem(valid((String) null)));
    assertThat(all, hasItem(valid("")));
    assertThat(all, hasItem(valid(" ")));
    assertThat(all, hasItem(valid("\t")));
    assertThat(all, hasItem(valid(StringGenerator.gen(fill, 8077))));

    assertThat(all, hasItem(invalid(StringGenerator.gen(fill, 4)))); // invalid
    assertThat(all, hasItem(valid(StringGenerator.gen(fill, 5)))); // valid
  }
Example #2
0
 @Test
 public void withMinAndMaxLengthAndFilterNotNull() throws Exception {
   sut.setNullIsAValue(false);
   sut.minLength(5);
   sut.maxLength(15);
   List<Representant<String>> all = sut.getRepresentatives(null);
   assertEquals(8, all.size());
   assertThat(all, not(hasItem(valid((String) null))));
   assertThat(all, hasItem(valid("")));
   assertThat(all, hasItem(valid(" ")));
   assertThat(all, hasItem(valid("\t")));
   // min
   assertThat(all, hasItem(invalid(StringGenerator.gen(fill, 4)))); // invalid
   assertThat(all, hasItem(valid(StringGenerator.gen(fill, 5)))); // valid
   // middle
   assertThat(all, hasItem(valid(StringGenerator.gen(fill, 10)))); // valid
   // max
   assertThat(all, hasItem(valid(StringGenerator.gen(fill, 15)))); // valid
   assertThat(all, hasItem(invalid(StringGenerator.gen(fill, 16)))); // invalid
 }
Example #3
0
  @Test
  public void withMinLength() throws Exception {
    sut.required(true);
    sut.noEmptyStringCheck();
    sut.setNullIsAValue(false);
    sut.assumeWhitspacesEqalsAnEmptyString(false);
    sut.maxLength(200);
    sut.minLength(1);
    List<Representant<String>> valid = sut.getRepresentatives(RepresentantType.VALID);
    List<Representant<String>> invalid = sut.getRepresentatives(RepresentantType.INVALID);
    assertEquals(3, valid.size());
    assertEquals(4, invalid.size());

    assertThat(valid, hasItem(valid("J")));
    assertThat(valid, hasItem(valid(StringGenerator.gen(fill, 199))));
    assertThat(valid, hasItem(valid(StringGenerator.gen(fill, 200))));

    assertThat(invalid, hasItem(invalid("")));
    assertThat(invalid, hasItem(invalid(" ")));
    assertThat(invalid, hasItem(invalid("\t")));
    assertThat(invalid, hasItem(invalid(StringGenerator.gen(fill, 201))));
  }