Example #1
0
  @Test
  public void withNotEmpty() throws Exception {
    sut.required(true);
    sut.noEmptyStringCheck();
    sut.setNullIsAValue(false);
    sut.assumeWhitspacesEqualsAnEmptyString();
    sut.maxLength(200);
    List<Representant<String>> valid = sut.getRepresentatives(RepresentantType.VALID);
    List<Representant<String>> invalid = sut.getRepresentatives(RepresentantType.INVALID);
    assertEquals(1, valid.size());
    assertEquals(3, invalid.size());

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

    assertThat(invalid, hasItem(invalid(" ")));
    assertThat(invalid, hasItem(invalid("\t")));
    assertThat(invalid, hasItem(invalid(StringGenerator.gen(fill, 201))));
  }
Example #2
0
 @Test
 public void withoutParametersAndFilter() throws Exception {
   List<Representant<String>> all = sut.getRepresentatives(null);
   assertEquals(5, 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))));
 }
Example #3
0
  @Test
  public void withMaxLengthAndFilterNotNull() throws Exception {
    sut.setNullIsAValue(false).maxLength(15);
    List<Representant<String>> all = sut.getRepresentatives(null);
    assertEquals(5, all.size());
    assertThat(all, not(hasItem((valid((String) null)))));
    assertThat(all, hasItem(valid("")));
    assertThat(all, hasItem(valid(" ")));
    assertThat(all, hasItem(valid("\t")));

    assertThat(all, hasItem(valid(StringGenerator.gen(fill, 15)))); // valid
    assertThat(all, hasItem(invalid(StringGenerator.gen(fill, 16)))); // invalid
  }
Example #4
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
  }