コード例 #1
0
  @Test
  public void displaysCorrectFailureDescriptionForProbeWhenElementDoesNotExist() {
    final StringDescription description = new StringDescription();

    probe.describeFailureTo(description);

    assertThat(description.toString(), is("The element does not exist"));
  }
コード例 #2
0
ファイル: XOrChainMatcherTest.java プロジェクト: derari/cthul
  @Test
  public void test_mismatch_description() {
    StringDescription desc = new StringDescription();
    either(greaterThan(1)).xor(lessThan(5)).describeMismatch(3, desc);
    assertThat(desc.toString(), is("was a value greater than <1> and was a value less than <5>"));

    desc = new StringDescription();
    either(greaterThan(5)).xor(lessThan(1)).describeMismatch(3, desc);
    assertThat(desc.toString(), is("<3> was less than <5> and <3> was greater than <1>"));
  }
コード例 #3
0
 @Test
 public void assertThatSmallGraphIsDescribable() {
   Graph graph1 = makeSmallGraph("A");
   Matcher<? super Graph> matcher = deeplyEqualTo(graph1);
   StringDescription description = new StringDescription();
   matcher.describeTo(description);
   assertThat(
       description.toString(),
       allOf(
           startsWith("{" + System.getProperty("line.separator") + "  nodes ["),
           containsString("value is <"),
           containsString("neighbors ["),
           containsString("&Node<A-1>")));
 }
コード例 #4
0
 @Test
 public void mismatchFormulaCell() {
   hasSameCell(createFormulaCell(0, 3, "2+2")).matchesSafely(row, description);
   assertThat(
       description.toString(),
       is("cell at \"D1\" contained <Formula:2+3> expected <Formula:2+2>"));
 }
コード例 #5
0
 @Test
 public void mismatch() throws IOException {
   hasSameRowsAs(sheetWithThreeRows).matchesSafely(sheetWithDifferingValues, description);
   assertThat(
       description.toString(),
       containsString("cell at \"A2\" contained <\"XXX\"> expected <\"Row 2\">"));
 }
コード例 #6
0
 @Test
 public void mismatchDateCell() {
   assertTimezone(is("UTC"));
   hasSameCell(createCell(0, 5, createDate(21, AUGUST, 2012))).matchesSafely(row, description);
   assertThat(
       description.toString(),
       is(
           "cell at \"F1\" contained <Wed Aug 22 00:00:00 UTC 2012> expected <Tue Aug 21 00:00:00 UTC 2012>"));
 }
コード例 #7
0
  @Test
  public void displaysCorrectFailureDescriptionForProbeWhenElementDoesNotMatch() {
    final StringDescription description = new StringDescription();

    final WebElement webElement = context.mock(WebElement.class);

    context.checking(
        new Expectations() {
          {
            oneOf(element).find();
            will(returnValue(webElement));

            oneOf(elementMatcher).describeTo(description);
          }
        });

    probe.doProbe();
    probe.describeFailureTo(description);

    assertThat(description.toString(), is("The element does not match "));
  }
コード例 #8
0
  @Test
  public void unmetExpectationUsingHamcrestMatcherAsPredicate() {
    try {
      expect("foo").to(match(startsWith("d")));
    } catch (AssertionError expected) {
      assertEquals(
          "[foo] did not satisfy [" + StringDescription.toString(startsWith("d")) + ']',
          expected.getMessage());
      return;
    }

    fail();
  }
コード例 #9
0
 @Test
 public void mismatchNumericCell() {
   hasSameCell(createCell(0, 4, 341.5D)).matchesSafely(row, description);
   assertThat(description.toString(), is("cell at \"E1\" contained <34.5D> expected <341.5D>"));
 }
コード例 #10
0
 @Test
 public void mismatchOnMissingRow() {
   hasSameRowsAs(sheetWithThreeRows).matchesSafely(sheetWithTwoRows, description);
   assertThat(description.toString(), is("row <3> is missing in sheet \"Sheet1\""));
 }
コード例 #11
0
 @Test
 public void mismatchBooleanCell() {
   hasSameCell(createCell(0, 1, false)).matchesSafely(row, description);
   assertThat(description.toString(), is("cell at \"B1\" contained <TRUE> expected <FALSE>"));
 }
コード例 #12
0
 private void assertMismatchDescription(String expectedDescription, Object actual) {
   StringDescription description = new StringDescription();
   matcher.describeMismatch(actual, description);
   assertEquals(expectedDescription, description.toString());
 }
コード例 #13
0
 public String getMessage() {
   return StringDescription.asString(this);
 }
コード例 #14
0
 @Test
 public void describe() {
   hasSameCell(createCell(0, 0, "XXX")).describeTo(description);
   assertThat(description.toString(), is("equality of cell \"A1\""));
 }
コード例 #15
0
 private <T> String describeMismatch(Matcher<T> matcher, T object) {
   StringDescription description = new StringDescription();
   matcher.describeMismatch(object, description);
   return description.toString();
 }
コード例 #16
0
 @Test
 public void mismatchMissingCell() {
   hasSameCell(createCell(0, 0, "XXX")).matchesSafely(row, description);
   assertThat(description.toString(), is("cell at \"A1\" contained <nothing> expected <\"XXX\">"));
 }
コード例 #17
0
 @Test
 public void description() throws IOException {
   hasSameRowsAs(sheetWithThreeRows).describeTo(description);
   assertThat(description.toString(), containsString("equality on all rows in \"Sheet1\""));
 }
コード例 #18
0
 @Test
 public void mismatchFormulaErrorCell() {
   hasSameCell(createCell(0, 2, (byte) 0x00)).matchesSafely(row, description);
   assertThat(description.toString(), is("cell at \"C1\" contained <Error:7> expected <Error:0>"));
 }
コード例 #19
0
 private <S> String descriptionOf(Matcher<S> matcher, S value) {
   StringDescription description = new StringDescription();
   matcher.describeMismatch(value, description);
   return description.toString();
 }