@Test public void displaysCorrectFailureDescriptionForProbeWhenElementDoesNotExist() { final StringDescription description = new StringDescription(); probe.describeFailureTo(description); assertThat(description.toString(), is("The element does not exist")); }
@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>")); }
@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>"))); }
@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>")); }
@Test public void mismatch() throws IOException { hasSameRowsAs(sheetWithThreeRows).matchesSafely(sheetWithDifferingValues, description); assertThat( description.toString(), containsString("cell at \"A2\" contained <\"XXX\"> expected <\"Row 2\">")); }
@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>")); }
@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 ")); }
@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(); }
@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>")); }
@Test public void mismatchOnMissingRow() { hasSameRowsAs(sheetWithThreeRows).matchesSafely(sheetWithTwoRows, description); assertThat(description.toString(), is("row <3> is missing in sheet \"Sheet1\"")); }
@Test public void mismatchBooleanCell() { hasSameCell(createCell(0, 1, false)).matchesSafely(row, description); assertThat(description.toString(), is("cell at \"B1\" contained <TRUE> expected <FALSE>")); }
private void assertMismatchDescription(String expectedDescription, Object actual) { StringDescription description = new StringDescription(); matcher.describeMismatch(actual, description); assertEquals(expectedDescription, description.toString()); }
public String getMessage() { return StringDescription.asString(this); }
@Test public void describe() { hasSameCell(createCell(0, 0, "XXX")).describeTo(description); assertThat(description.toString(), is("equality of cell \"A1\"")); }
private <T> String describeMismatch(Matcher<T> matcher, T object) { StringDescription description = new StringDescription(); matcher.describeMismatch(object, description); return description.toString(); }
@Test public void mismatchMissingCell() { hasSameCell(createCell(0, 0, "XXX")).matchesSafely(row, description); assertThat(description.toString(), is("cell at \"A1\" contained <nothing> expected <\"XXX\">")); }
@Test public void description() throws IOException { hasSameRowsAs(sheetWithThreeRows).describeTo(description); assertThat(description.toString(), containsString("equality on all rows in \"Sheet1\"")); }
@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>")); }
private <S> String descriptionOf(Matcher<S> matcher, S value) { StringDescription description = new StringDescription(); matcher.describeMismatch(value, description); return description.toString(); }