Example #1
0
 @Test
 public void withOwnEmptySpecInValidNotNull() throws Exception {
   sut.setNullIsAValue(false);
   sut.setWhitspaceStrings("rw");
   List<Representant<String>> all = sut.getInValidRepresentations();
   assertEquals(0, all.size());
 }
Example #2
0
 @Test
 public void withOwnEmptySpecInValidAndRequiredWithoutEmptyString() throws Exception {
   sut.setWhitspaceStrings("rw");
   sut.noEmptyStringCheck();
   sut.required(true);
   List<Representant<String>> all = sut.getInValidRepresentations();
   assertEquals(2, all.size());
   assertThat(all, hasItem(invalid((String) null)));
   assertThat(all, hasItem(invalid("rw")));
 }
Example #3
0
 @Test
 public void withOwnEmptySpecValid() throws Exception {
   sut.setWhitspaceStrings("rw");
   List<Representant<String>> all = sut.getValidRepresentations();
   assertEquals(4, all.size());
   assertThat(all, hasItem(valid((String) null)));
   assertThat(all, hasItem(valid("")));
   assertThat(all, hasItem(valid("rw")));
   assertThat(all, hasItem(valid(StringGenerator.gen(fill, 8077))));
 }
Example #4
0
 @Test
 public void withoutParametersAndFilterNotNull() throws Exception {
   sut.setNullIsAValue(false);
   List<Representant<String>> all = sut.getRepresentatives(null);
   assertEquals(4, 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, 8077))));
 }
Example #5
0
 @Test
 public void withOwnEmptySpecInValidAndRequiredNotNull() throws Exception {
   sut.setNullIsAValue(false);
   sut.setWhitspaceStrings("rw");
   sut.required(true);
   List<Representant<String>> all = sut.getInValidRepresentations();
   assertEquals(2, all.size());
   assertThat(all, not(hasItem(invalid((String) null))));
   assertThat(all, hasItem(invalid("")));
   assertThat(all, hasItem(invalid("rw")));
 }
Example #6
0
 @Test
 public void withOwnEmptyStringValidNotNull() throws Exception {
   sut.setNullIsAValue(false);
   sut.setWhitspaceStrings("rw");
   sut.setEmptyString("-");
   List<Representant<String>> all = sut.getValidRepresentations();
   assertEquals(3, all.size());
   assertThat(all, not(hasItem(valid((String) null))));
   assertThat(all, hasItem(valid("-")));
   assertThat(all, hasItem(valid("rw")));
   assertThat(all, hasItem(valid(StringGenerator.gen(fill, 8077))));
 }
Example #7
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 #8
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 #9
0
 @Test
 public void whitespacesAreToTrimOnRequiredNotNull() throws Exception {
   sut.assumeWhitspacesEqualsAnEmptyString().setNullIsAValue(false).required(false);
   { // valid
     List<Representant<String>> all = sut.getValidRepresentations();
     assertEquals(4, 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, 8077))));
   }
   { // invalid
     List<Representant<String>> all = sut.getInValidRepresentations();
     assertEquals(0, all.size());
   }
 }
Example #10
0
  @Test
  public void whitespacesAreNotToTrim() throws Exception {
    sut.assumeWhitspacesEqualsAnEmptyString();
    { // valid
      List<Representant<String>> all = sut.getValidRepresentations();
      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))));
    }
    { // invalid
      List<Representant<String>> all = sut.getInValidRepresentations();
      assertEquals(0, all.size());
    }
  }
Example #11
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 #12
0
 @Test
 public void trimAndFilltoMaxLength() throws Exception {
   sut.trim(true);
   sut.maxLength(97);
   sut.noEmptyStringCheck();
   sut.setWhitspaceStrings("");
   sut.setNullIsAValue(false);
   { // valid
     List<Representant<String>> all = sut.getValidRepresentations();
     assertEquals(2, all.size());
     assertThat(all, hasItem(valid("")));
     for (Representant<String> representant : all) {
       assertThat(representant.getValue(), equalTo(representant.getValue().trim()));
     }
   }
   {
     List<Representant<String>> all = sut.getInValidRepresentations();
     assertEquals(1, all.size());
   }
 }