コード例 #1
0
ファイル: OfTypeStringTest.java プロジェクト: dimitarp/stu
  @Test
  public void withMaxLengthAndFilter() throws Exception {
    sut.maxLength(15);
    List<Representant<String>> all = sut.getRepresentatives(null);
    assertEquals(6, 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, 15)))); // valid
    assertThat(all, hasItem(invalid(StringGenerator.gen(fill, 16)))); // invalid
  }
コード例 #2
0
ファイル: OfTypeStringTest.java プロジェクト: dimitarp/stu
  @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))));
  }
コード例 #3
0
ファイル: OfTypeStringTest.java プロジェクト: dimitarp/stu
 @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());
   }
 }
コード例 #4
0
ファイル: OfTypeStringTest.java プロジェクト: dimitarp/stu
 @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
 }