File tree Expand file tree Collapse file tree
hamcrest-integration/src/main/java/org/hamcrest
hamcrest-unit-test/src/main/java/org/hamcrest Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" ?>
22<classpath >
33 <classpathentry kind =" src" path =" hamcrest-api/src/main/java" />
4+ <classpathentry kind =" src" path =" build/generated-code" />
45 <classpathentry kind =" src" path =" hamcrest-generator/src/main/java" />
56 <classpathentry kind =" src" path =" hamcrest-examples/src/main/java" />
67 <classpathentry kind =" src" path =" hamcrest-integration/src/main/java" />
78 <classpathentry kind =" src" path =" hamcrest-library/src/main/java" />
89 <classpathentry kind =" src" path =" hamcrest-unit-test/src/main/java" />
910 <classpathentry kind =" lib" path =" lib/integration/easymock-2.2.jar" />
1011 <classpathentry kind =" lib" path =" lib/integration/jmock-1.10RC1.jar" />
11- <classpathentry kind =" lib" path =" lib/integration/junit-3.8.1.jar" />
1212 <classpathentry kind =" lib" path =" lib/integration/junit-4.0.jar" />
1313 <classpathentry kind =" lib" path =" lib/integration/testng-4.6-jdk15.jar" />
1414 <classpathentry kind =" con" path =" org.eclipse.jdt.launching.JRE_CONTAINER" />
Original file line number Diff line number Diff line change 44
55
66public class MatcherAssert {
7-
87 public static <T > void assertThat (T actual , Matcher <T > matcher ) {
8+ assertThat ("" , actual , matcher );
9+ }
10+
11+ public static <T > void assertThat (String name , T actual , Matcher <T > matcher ) {
912 if (!matcher .matches (actual )) {
1013 Description description = new StringDescription ();
14+ description .appendText (name );
1115 description .appendText ("\n Expected: " );
1216 matcher .describeTo (description );
13- description .appendText ("\n got : " ).appendValue (actual ).appendText ("\n " );
17+ description .appendText ("\n got : " ).appendValue (actual ).appendText ("\n " );
1418 throw new java .lang .AssertionError (description .toString ());
1519 }
1620 }
17-
1821}
Original file line number Diff line number Diff line change 1+ package org .hamcrest ;
2+
3+ import junit .framework .TestCase ;
4+ import static org .hamcrest .Matchers .*;
5+ import static org .hamcrest .MatcherAssert .assertThat ;
6+
7+ public class MatcherAssertTest extends TestCase {
8+ public void testIncludesDescriptionOfTestedValueInErrorMessage () {
9+ String expected = "expected" ;
10+ String actual = "actual" ;
11+
12+ String expectedMessage = "identifier\n Expected: \" expected\" \n got: \" actual\" \n " ;
13+
14+ try {
15+ assertThat ("identifier" , actual , equalTo (expected ));
16+ }
17+ catch (AssertionError e ) {
18+ assertEquals (expectedMessage , e .getMessage ());
19+ }
20+ }
21+
22+ public void testDescriptionCanBeElided () {
23+ String expected = "expected" ;
24+ String actual = "actual" ;
25+
26+ String expectedMessage = "\n Expected: \" expected\" \n got: \" actual\" \n " ;
27+
28+ try {
29+ assertThat (actual , equalTo (expected ));
30+ }
31+ catch (AssertionError e ) {
32+ assertEquals (expectedMessage , e .getMessage ());
33+ }
34+ }
35+ }
36+
You can’t perform that action at this time.
0 commit comments