Skip to content

Commit 53f97b9

Browse files
author
joe.walnes
committed
Structural changes: Created hamcrest-core.
* Moved all of hamcrest-api into hamcrest-core. * Moved all *.core matchers from hamcrest-library into hamcrest-core. * Moved essential integration, utility and base classes into hamcrest-core. * Created org.hamcrest.CoreMatchers static import class. * Beefed up JavaDoc of hamcrest-core. * Updated necessary docs and build for new structure. * Reversed dependency -> now core depends on generator tool (for CoreMatchers).
1 parent 24a365f commit 53f97b9

30 files changed

Lines changed: 312 additions & 79 deletions

‎BUILDING.txt‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ Steps:
4040
- Run 'ant library'. This generates additional Java coded
4141
necessary to compile.
4242
- Create a new project.
43-
- Add hamcrest-api/src/main, hamcrest-library/src/main,
44-
hamcrest-generator/src/main, hamcrest-integration/src/main,
45-
and build/generated-code as source directories.
46-
- Add hamcrest-unit-test/src/main as a test directory. If this is
47-
unsupported by the IDE, add it as another source
43+
- Add the following directories as source directories:
44+
hamcrest-core/src/main/java
45+
hamcrest-library/src/main/java
46+
hamcrest-generator/src/main/java
47+
hamcrest-integration/src/main/java
48+
build/hamcrest-core/generated-code
49+
build/hamcrest-library/generated-code
50+
- Add hamcrest-unit-test/src/main/java as a test directory.
51+
If this is unsupported by the IDE, add it as another source
4852
directory.
4953
- Include all jars in the lib directory in the classpath.
5054
- Compile as usual in the IDE.

‎CHANGES.txt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
== Version 1.1: In Development ==
22

3+
* Created hamcrest-core.jar (and removed hamcrest-api.jar).
4+
Moved core set of matchers (and, eq, not, etc) to this package to make
5+
it more practical for external libraries to embed hamcrest.
6+
7+
* Created CoreMatchers (static import sugar) in hamcrest-core.jar.
8+
9+
* StringBuilder can use any Appendable (not just StringBuffer).
10+
311
* Generator recognizes @Factory methods that return subclass of Matcher.
412
(Fix by David Saff)
513

‎README.txt‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ to create flexible expressions of intent in tests.
1616
Depending on how you intend to use Hamcrest, you should use
1717
different Jars.
1818

19-
* [hamcrest-api.jar]
19+
* [hamcrest-core.jar]
2020
This is the core API to be used by third-party framework
21-
providers. This excludes the implementations of Matchers.
22-
This API is stable and will rarely change.
21+
providers. This includes the a foundation set of matcher
22+
implementations for common operations.
23+
This API is stable and will rarely change. You will need
24+
this library as a minimum.
2325

2426
* [hamcrest-library.jar]
2527
The ever-growing library of Matcher implementations. This
@@ -62,7 +64,7 @@ Documentation can be found at:
6264
--[ Source ]-------------------------------------------------
6365

6466
The complete source for Hamcrest is bundled. This includes:
65-
* Matcher API [src/api]
67+
* Matcher core classes [src/core]
6668
* Matcher libary [src/library]
6769
* Matcher integrations [src/integration]
6870
* Syntactic sugar generator [src/generator]

‎build.xml‎

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,63 +21,84 @@
2121
<delete dir="build"/>
2222
</target>
2323

24-
<target name="api"
25-
description="Build API">
26-
<java-to-jar srcdir="hamcrest-api/src/main/java"
27-
destjar="build/hamcrest-api-${version}.jar"/>
28-
</target>
29-
3024
<target name="generator"
31-
depends="api"
3225
description="Build code generator tool">
3326
<java-to-jar srcdir="hamcrest-generator/src/main/java"
3427
destjar="build/hamcrest-generator-${version}.jar"
35-
classpath="build/hamcrest-api-${version}.jar"/>
28+
classpath="
29+
build/hamcrest-core-${version}.jar;
30+
"/>
31+
</target>
32+
33+
<target name="core"
34+
depends="generator"
35+
description="Build core Hamcrest library">
36+
<java-to-jar srcdir="hamcrest-core/src/main/java"
37+
destjar="build/hamcrest-core-${version}.jar"/>
38+
<!-- Generate one class with all static imports -->
39+
<mkdir dir="build/hamcrest-core/generated-code"/>
40+
<java classname="org.hamcrest.generator.config.XmlConfigurator"
41+
fork="yes"
42+
failonerror="yes"
43+
classpath="
44+
build/hamcrest-core-${version}.jar;
45+
build/hamcrest-generator-${version}.jar;
46+
">
47+
<arg value="core-matchers.xml"/>
48+
<arg value="hamcrest-core/src/main/java"/>
49+
<arg value="org.hamcrest.CoreMatchers"/>
50+
<arg value="build/hamcrest-core/generated-code"/>
51+
</java>
52+
<!-- Append to core jar -->
53+
<java-to-jar srcdir="build/hamcrest-core/generated-code"
54+
destjar="build/hamcrest-core-${version}.jar"
55+
classpath="build/hamcrest-core-${version}.jar"/>
3656
</target>
3757

3858
<target name="library"
39-
depends="api,generator"
59+
depends="core,generator"
4060
description="Build library of matchers">
4161
<java-to-jar srcdir="hamcrest-library/src/main/java"
4262
destjar="build/hamcrest-library-${version}.jar"
43-
classpath="build/hamcrest-api-${version}.jar"/>
63+
classpath="build/hamcrest-core-${version}.jar"/>
4464
<!-- Generate one class with all static imports -->
45-
<mkdir dir="build/generated-code"/>
65+
<mkdir dir="build/hamcrest-library/generated-code"/>
4666
<java classname="org.hamcrest.generator.config.XmlConfigurator"
4767
fork="yes"
4868
failonerror="yes"
4969
classpath="
50-
build/hamcrest-api-${version}.jar;
70+
build/hamcrest-core-${version}.jar;
5171
build/hamcrest-generator-${version}.jar;
52-
build/hamcrest-library-${version}.jar
72+
build/hamcrest-library-${version}.jar;
5373
">
5474
<arg value="matchers.xml"/>
75+
<arg value="hamcrest-library/src/main/java"/>
5576
<arg value="org.hamcrest.Matchers"/>
56-
<arg value="build/generated-code"/>
77+
<arg value="build/hamcrest-library/generated-code"/>
5778
</java>
5879
<!-- Append to library jar -->
59-
<java-to-jar srcdir="build/generated-code"
80+
<java-to-jar srcdir="build/hamcrest-library/generated-code"
6081
destjar="build/hamcrest-library-${version}.jar"
61-
classpath="build/hamcrest-api-${version}.jar"/>
82+
classpath="build/hamcrest-core-${version}.jar"/>
6283
</target>
6384

6485
<target name="integration"
65-
depends="api, library"
86+
depends="core, library"
6687
description="Build integration with external tools">
6788
<java-to-jar srcdir="hamcrest-integration/src/main/java"
6889
destjar="build/hamcrest-integration-${version}.jar"
6990
classpath="
70-
build/hamcrest-api-${version}.jar;
91+
build/hamcrest-core-${version}.jar;
7192
build/hamcrest-library-${version}.jar"/>
7293
</target>
7394

7495
<target name="unit-test"
75-
depends="api, library, integration, generator"
96+
depends="core, library, integration, generator"
7697
description="Build and run unit tests.">
7798
<java-to-jar srcdir="hamcrest-unit-test/src/main/java"
7899
destjar="build/hamcrest-unit-test-${version}.jar"
79100
classpath="
80-
build/hamcrest-api-${version}.jar;
101+
build/hamcrest-core-${version}.jar;
81102
build/hamcrest-library-${version}.jar;
82103
build/hamcrest-integration-${version}.jar;
83104
build/hamcrest-generator-${version}.jar"/>
@@ -87,7 +108,7 @@
87108
<fileset dir="lib/integration">
88109
<include name="*.jar"/>
89110
</fileset>
90-
<pathelement path="build/hamcrest-api-${version}.jar"/>
111+
<pathelement path="build/hamcrest-core-${version}.jar"/>
91112
<pathelement path="build/hamcrest-library-${version}.jar"/>
92113
<pathelement path="build/hamcrest-integration-${version}.jar"/>
93114
<pathelement path="build/hamcrest-generator-${version}.jar"/>
@@ -102,29 +123,29 @@
102123
</target>
103124

104125
<target name="examples"
105-
depends="api, library, integration"
126+
depends="core, library, integration"
106127
description="Build and run unit tests.">
107128
<java-to-jar srcdir="hamcrest-examples/src/main/java"
108129
destjar="build/hamcrest-examples-${version}.jar"
109130
classpath="
110-
build/hamcrest-api-${version}.jar;
131+
build/hamcrest-core-${version}.jar;
111132
build/hamcrest-library-${version}.jar;
112133
build/hamcrest-integration-${version}.jar"/>
113134
</target>
114135

115136
<target name="bigjar"
116-
depends="api, library, integration, generator"
117-
description="Build a single Jar (hamcrest-all.jar) that contains api, library, generator and integration.">
137+
depends="core, library, integration, generator"
138+
description="Build a single Jar (hamcrest-all.jar) that contains core, library, generator and integration.">
118139
<jar jarfile="build/hamcrest-all-${version}.jar" duplicate="preserve">
119-
<fileset dir="build/temp/build/hamcrest-api-${version}.jar.contents"/>
140+
<fileset dir="build/temp/build/hamcrest-core-${version}.jar.contents"/>
120141
<fileset dir="build/temp/build/hamcrest-library-${version}.jar.contents"/>
121142
<fileset dir="build/temp/build/hamcrest-generator-${version}.jar.contents"/>
122143
<fileset dir="build/temp/build/hamcrest-integration-${version}.jar.contents"/>
123144
</jar>
124145
</target>
125146

126147
<target name="package"
127-
depends="api,generator,library,integration,bigjar,unit-test,examples"
148+
depends="core,generator,library,integration,bigjar,unit-test,examples"
128149
description="Package for distribution">
129150
<zip zipfile="build/hamcrest-${version}.zip">
130151
<zipfileset dir="." prefix="hamcrest-${version}">
@@ -135,7 +156,7 @@
135156
<include name="matchers.xml"/>
136157
</zipfileset>
137158
<zipfileset dir="build" prefix="hamcrest-${version}">
138-
<include name="hamcrest-api-${version}.jar"/>
159+
<include name="hamcrest-core-${version}.jar"/>
139160
<include name="hamcrest-generator-${version}.jar"/>
140161
<include name="hamcrest-library-${version}.jar"/>
141162
<include name="hamcrest-integration-${version}.jar"/>
@@ -151,7 +172,7 @@
151172
<include name="matchers.xml"/>
152173
</tarfileset>
153174
<tarfileset dir="build" prefix="hamcrest-${version}">
154-
<include name="hamcrest-api-${version}.jar"/>
175+
<include name="hamcrest-core-${version}.jar"/>
155176
<include name="hamcrest-generator-${version}.jar"/>
156177
<include name="hamcrest-library-${version}.jar"/>
157178
<include name="hamcrest-integration-${version}.jar"/>
@@ -171,7 +192,7 @@
171192
</fileset>
172193
</classpath>
173194

174-
<packageset dir="hamcrest-api/src/main/java"/>
195+
<packageset dir="hamcrest-core/src/main/java"/>
175196
<packageset dir="hamcrest-library/src/main/java" excludes="org/hamcrest/internal"/>
176197
<packageset dir="hamcrest-integration/src/main/java"/>
177198
<packageset dir="build/generated-code"/>

‎core-matchers.xml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<matchers>
2+
3+
<!-- Core -->
4+
<factory class="org.hamcrest.core.Is"/>
5+
<factory class="org.hamcrest.core.IsNot"/>
6+
<factory class="org.hamcrest.core.IsEqual"/>
7+
<factory class="org.hamcrest.core.IsInstanceOf"/>
8+
<factory class="org.hamcrest.core.AllOf"/>
9+
<factory class="org.hamcrest.core.AnyOf"/>
10+
<factory class="org.hamcrest.core.IsSame"/>
11+
<factory class="org.hamcrest.core.IsAnything"/>
12+
<factory class="org.hamcrest.core.IsNull"/>
13+
<factory class="org.hamcrest.core.DescribedAs"/>
14+
15+
</matchers>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Copyright (c) 2000-2006 hamcrest.org
2+
*/
3+
package org.hamcrest;
4+
5+
/**
6+
* BaseClass for all Matcher implementations.
7+
*
8+
* @see Matcher
9+
*/
10+
public abstract class BaseMatcher<T> implements Matcher<T> {
11+
12+
/**
13+
* @see Matcher#_dont_implement_Matcher___instead_extend_BaseMatcher_()
14+
*/
15+
public final void _dont_implement_Matcher___instead_extend_BaseMatcher_() {
16+
// See Matcher interface for an explanation of this method.
17+
}
18+
19+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.hamcrest;
2+
3+
/**
4+
* A description of a Matcher. A Matcher will describe itself to a description
5+
* which can later be used for reporting.
6+
*
7+
* @see Matcher#describeTo(Description)
8+
*/
9+
public interface Description {
10+
11+
/**
12+
* Appends some plain text to the description.
13+
*/
14+
Description appendText(String text);
15+
16+
/**
17+
* Appends an arbitary value to the description.
18+
*/
19+
Description appendValue(Object value);
20+
21+
/**
22+
* Appends a list of values to the description.
23+
*/
24+
<T> Description appendValueList(String start, String separator, String end,
25+
T... values);
26+
27+
/**
28+
* Appends a list of values to the description.
29+
*/
30+
<T> Description appendValueList(String start, String separator, String end,
31+
Iterable<T> values);
32+
33+
/**
34+
* Appends a list of {@link org.hamcrest.SelfDescribing} objects
35+
* to the description.
36+
*/
37+
Description appendList(String start, String separator, String end,
38+
Iterable<? extends SelfDescribing> values);
39+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.hamcrest;
2+
3+
import static java.lang.annotation.ElementType.METHOD;
4+
import java.lang.annotation.Retention;
5+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Marks a Hamcrest static factory method so tools recognise them.
10+
* A factory method is an equivalent to a named constructor.
11+
*
12+
* @author Joe Walnes
13+
*/
14+
@Retention(RUNTIME)
15+
@Target({METHOD})
16+
public @interface Factory {
17+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* Copyright (c) 2000-2006 hamcrest.org
2+
*/
3+
package org.hamcrest;
4+
5+
/**
6+
* A matcher over acceptable values.
7+
* A matcher is able to describe itself to give feedback when it fails.
8+
* <p/>
9+
* Matcher implementations should <b>NOT directly implement this interface</b>.
10+
* Instead, <b>extend</b> the {@link BaseMatcher} abstract class,
11+
* which will ensure that the Matcher API can grow to support
12+
* new features and remain compatible with all Matcher implementations.
13+
* <p/>
14+
* For easy access to common Matcher implementations, use the static factory
15+
* methods in {@link CoreMatchers}.
16+
*
17+
* @see CoreMatchers
18+
* @see BaseMatcher
19+
*/
20+
@SuppressWarnings({"unused", "UnusedDeclaration"})
21+
public interface Matcher<T> extends SelfDescribing {
22+
23+
/**
24+
* Evaluates the matcher for argument <var>item</var>.
25+
* <p/>
26+
* This method matches against Object, instead of the generic type T. This is
27+
* because the caller of the Matcher does not know at runtime what the type is
28+
* (because of type erasure with Java generics). It is down to the implementations
29+
* to check the correct type.
30+
*
31+
* @param item the object against which the matcher is evaluated.
32+
* @return <code>true</code> if <var>item</var> matches, otherwise <code>false</code>.
33+
*
34+
* @see BaseMatcher
35+
*/
36+
boolean matches(Object item);
37+
38+
/**
39+
* This method simply acts a friendly reminder not to implement Matcher directly and
40+
* instead extend BaseMatcher. It's easy to ignore JavaDoc, but a bit harder to ignore
41+
* compile errors .
42+
*
43+
* @see Matcher for reasons why.
44+
* @see BaseMatcher
45+
*/
46+
void _dont_implement_Matcher___instead_extend_BaseMatcher_();
47+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.hamcrest;
2+
3+
/**
4+
* The ability of an object to describe itself.
5+
*/
6+
public interface SelfDescribing {
7+
/**
8+
* Generates a description of the object. The description may be part of a
9+
* a description of a larger object of which this is just a component, so it
10+
* should be worded appropriately.
11+
*
12+
* @param description
13+
* The description to be built or appended to.
14+
*/
15+
void describeTo(Description description);
16+
}

0 commit comments

Comments
 (0)