11package org .hamcrest .generator .config ;
22
3+ import java .io .StringReader ;
4+ import java .util .ArrayList ;
5+ import java .util .List ;
6+
37import junit .framework .TestCase ;
8+
9+ import org .hamcrest .Description ;
410import org .hamcrest .Factory ;
511import org .hamcrest .Matcher ;
6- import org .hamcrest .core .CombinableMatcher ;
712import org .hamcrest .generator .FactoryMethod ;
813import org .hamcrest .generator .FactoryWriter ;
914import org .hamcrest .generator .SugarConfiguration ;
1015import org .xml .sax .InputSource ;
1116
12- import java .io .StringReader ;
13- import java .util .ArrayList ;
14- import java .util .List ;
15-
16- import static org .hamcrest .MatcherAssert .assertThat ;
17- import static org .hamcrest .core .IsCollectionContaining .hasItem ;
18-
1917public class XmlConfiguratorTest extends TestCase {
2018
2119 private MockSugarConfiguration sugarConfiguration ;
@@ -35,12 +33,10 @@ public void testAddsMatcherFactoryMethodsToConfiguration() throws Exception {
3533 " <factory class='org.hamcrest.generator.config.XmlConfiguratorTest$AnotherMatcher'/>" +
3634 "</matchers>" ));
3735
38- assertThat (sugarConfiguration .factoryMethods (),
39- hasItem (new FactoryMethod (SomeMatcher .class .getName ().replace ('$' , '.' ), "matcher1" , "org.hamcrest.Matcher" )));
40- assertThat (sugarConfiguration .factoryMethods (),
41- hasItem (new FactoryMethod (SomeMatcher .class .getName ().replace ('$' , '.' ), "matcher2" , "org.hamcrest.Matcher" )));
42- assertThat (sugarConfiguration .factoryMethods (),
43- hasItem (new FactoryMethod (AnotherMatcher .class .getName ().replace ('$' , '.' ), "matcher3" , "org.hamcrest.CombinableMatcher" )));
36+ final List <FactoryMethod > result = sugarConfiguration .factoryMethods ();
37+ assertTrue (result .contains (new FactoryMethod (SomeMatcher .class .getName ().replace ('$' , '.' ), "matcher1" , "org.hamcrest.Matcher" )));
38+ assertTrue (result .contains (new FactoryMethod (SomeMatcher .class .getName ().replace ('$' , '.' ), "matcher2" , "org.hamcrest.Matcher" )));
39+ assertTrue (result .contains (new FactoryMethod (AnotherMatcher .class .getName ().replace ('$' , '.' ), "matcher3" , "org.hamcrest.MyMatcher" )));
4440 }
4541
4642 private static InputSource createXml (String xml ) {
@@ -51,30 +47,24 @@ private static InputSource createXml(String xml) {
5147
5248 @ SuppressWarnings ("rawtypes" )
5349 public static class SomeMatcher {
54- @ Factory
55- public static Matcher matcher1 () {
56- return null ;
57- }
58-
59- @ Factory
60- public static Matcher matcher2 () {
61- return null ;
62- }
50+ @ Factory public static Matcher matcher1 () { return null ; }
51+ @ Factory public static Matcher matcher2 () { return null ; }
6352 }
6453
6554 @ SuppressWarnings ("rawtypes" )
66- public static class AnotherMatcher {
67- @ Factory
68- public static CombinableMatcher matcher3 () {
69- return null ;
70- }
55+ public static class AnotherMatcher <T > implements Matcher <T > {
56+ @ Override public void describeTo (Description description ) { }
57+ @ Override public boolean matches (Object item ) { return false ; }
58+ @ Override public void describeMismatch (Object item , Description mismatchDescription ) { }
59+ @ Override @ Deprecated public void _dont_implement_Matcher___instead_extend_BaseMatcher_ () { }
60+ @ Factory public static AnotherMatcher matcher3 () { return null ; }
7161 }
7262
7363 /**
7464 * Simple 'record and check' style mock. Not using a mocking library to avoid
75- * cyclical dependency between mocking library and hamcrest.
65+ * cyclic dependency between mocking library and hamcrest.
7666 */
77- private static class MockSugarConfiguration implements SugarConfiguration {
67+ private static final class MockSugarConfiguration implements SugarConfiguration {
7868
7969 private final List <FactoryMethod > seenFactoryMethods = new ArrayList <FactoryMethod >();
8070 private final List <FactoryWriter > seenFactoryWriters = new ArrayList <FactoryWriter >();
@@ -100,5 +90,4 @@ public List<FactoryMethod> factoryMethods() {
10090 return seenFactoryMethods ;
10191 }
10292 }
103-
10493}
0 commit comments