Skip to content

Commit 1260407

Browse files
author
joeretro
committed
Initial checkin
0 parents  commit 1260407

70 files changed

Lines changed: 2771 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎BUILDING.txt‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
**********************
2+
********************* Building Ham Crest ********************
3+
**********************
4+
5+
--[ Build requirements ]---000-------------------------------
6+
7+
* JDK 1.5
8+
Note: that this is a buildtime dependency for 1.5 specific
9+
features. However the final built jars should run on 1.4
10+
and 1.3 JVMs with some features unavailable.
11+
12+
* Ant 1.6 or greater
13+
To enable testing support, ensure junit.jar exists in
14+
ANT_HOME/lib.
15+
16+
17+
--[ Building from the command line ]-------------------------
18+
19+
Execute the default ant target:
20+
ant
21+
22+
This will do a full clean build, run all tests and (if
23+
successful) package up a distribution. The resulting builds
24+
reside in the 'build' directory.
25+
26+
For a list of finer grained build operations:
27+
ant -projecthelp
28+
29+
The default version number used in the build is 'SNAPSHOT'.
30+
To override this, you can pass a property to ant:
31+
ant -Dversion=MY.OTHER.VERSION
32+
33+
34+
--[ Building from the IDE ]----------------------------------
35+
36+
It is possible to compile and test the source directly from
37+
popular IDEs, without resorting to the command line.
38+
39+
Steps:
40+
- Create a new project.
41+
- Add src/api, src/library and src/integration as source
42+
directories.
43+
- Add src/unit-test as a test directory. If this is
44+
unsupported by the IDE, add it as another source
45+
directory.
46+
- Include all jars in the lib directory in the classpath.
47+
- Compile as usual in the IDE.
48+
- If supported, run all tests under org.hamcrest from the
49+
IDEs JUnit runner.
50+
51+
52+
-------------------------------------------------------------
53+
-Nat Pryce and Joe Walnes
54+
http://hamcrest.org/

‎CHANGES.txt‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
* Signifies major change.
2+
- Signifies minor change.
3+
4+
=== Changes since jMock fork ===
5+
6+
[API Changes]
7+
* Constraint renamed to Matcher.
8+
* Constraint.eval() renamed to Matcher.match().
9+
* Packages moved from org.jmock.core.matcher to org.hamcrest.
10+
* Merged SelfDescribing into Matcher interface.
11+
* SelfDescribing.describe() no longer returns a StringBuffer. Simpler for users to implement.
12+
13+
[Library Changes]
14+
* Matchers categorised and broken into subpackages (core, collection, number, object, text).
15+
* Added MatcherSugar class with static helpers for syntactic sugar (based on jmock MockObjectSupportTestCase).
16+
- Added MatcherSugar.IS_TRUE and MatcherSugar.IS_FALSE.
17+
- Added Always matcher (based upon NMock2 AlwaysMatcher).
18+
- Added DescribedAs matcher (based upon NMock2 DescriptionOverride).
19+
- Added IsEqualsIgnoringCase matcher (based upon NMock1 IsEqualIgnoreCase).
20+
- Added IsEqualsIgnoringWhiteSpace matcher (based upon NMock1 IsEqualIgnoreWhiteSpace).
21+
22+
[Integration Changes]
23+
* Added MatcherAssert, for assertThat(Object, Matcher) in JUnit.
24+
25+
[Misc]
26+
* Split code into different JARs
27+
* Simplified build and directory layout.

‎LICENSE.txt‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(BSD Style License)
2+
3+
Copyright (c) 2000-2006, HamCrest.org
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
Redistributions of source code must retain the above copyright notice, this list of
10+
conditions and the following disclaimer. Redistributions in binary form must reproduce
11+
the above copyright notice, this list of conditions and the following disclaimer in
12+
the documentation and/or other materials provided with the distribution.
13+
14+
Neither the name of HamCrest nor the names of its contributors may be used to endorse
15+
or promote products derived from this software without specific prior written
16+
permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
19+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21+
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
26+
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27+
DAMAGE.

‎README.txt‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
*************
3+
********************** Ham Crest **********************
4+
*************
5+
6+
"TODO: catchy phrase"
7+
8+
<http://hamcrest.org>
9+
10+
--[ What is Ham Crest? ]-------------------------------------
11+
12+
TODO
13+
14+
--[ Binaries ]-----------------------------------------------
15+
16+
Depending on how you intend to use Ham Crest, you should use
17+
different Jars.
18+
19+
* [hamcrest-api.jar]
20+
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.
23+
24+
* [hamcrest-library.jar]
25+
The ever-growing library of Matcher implementations.
26+
This should be
27+
28+
TODO: Finish this
29+
30+
All libraries in the 'lib' directory are used at build time,
31+
or are optional extras used for tighter integration with
32+
third party libraries.
33+
34+
ALL OF THE DEPENDENCIES ARE OPTIONAL.
35+
36+
37+
--[ Documentation ]------------------------------------------
38+
39+
Documentation can be found at http://hamcrest.org/
40+
41+
42+
--[ Source ]-------------------------------------------------
43+
44+
The complete source for Ham Crest is bundled. This includes:
45+
* Matcher API [src/api]
46+
* Matcher libary [src/library]
47+
* Matcher integrations [src/integration]
48+
* Unit tests [src/unit-test]
49+
* Ant build file [build.xml]
50+
* Dependencies [lib]
51+
52+
To build, please read BUILDING.txt
53+
54+
-------------------------------------------------------------
55+
-Nat Pryce and Joe Walnes
56+
http://hamcrest.org/
57+

‎TODO.txt‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
* Add matchers for dealing with collections allowing flexibility over:
2+
- ordered/not-ordered
3+
- use of matchers for item checking
4+
- contains these items, at least
5+
- contains these items, exclusively
6+
- contains none of thes items
7+
- all items should match a specific matcher
8+
9+
* Collection based matchers should not care about implementation of datastructure. Polymorphism across:
10+
- arrays
11+
- collections
12+
- iterators
13+
- iterables (jdk 1.5)
14+
15+
* String matchers
16+
- case insensitive
17+
- whitespace insensitive
18+
- reg exp matching
19+
20+
* XML
21+
- is wellformed XML
22+
- xpath expressions for XML/HTML strings and existing Nodes
23+
24+
* Invocation
25+
- method called
26+
- ... with particular arguments
27+
28+
* JDK 1.5 Enums
29+
30+
* Sugar for between(12, 20)
31+
32+
* ComparisonMatcher (See NMock2)
33+
34+
* Sugar for new matchers

‎build.xml‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<project name="hamcrest" default="all">
2+
3+
<property name="version" value="SNAPSHOT"/>
4+
5+
<target name="all" depends="clean, build,test,package"
6+
description="Performs clean build, test and package for distribution"/>
7+
8+
<target name="clean" description="Clean up all built files">
9+
<delete dir="build"/>
10+
</target>
11+
12+
<target name="build" description="Build project">
13+
<mkdir dir="build"/>
14+
<java-to-jar srcdir="src/api" destjar="build/hamcrest-api-${version}.jar"/>
15+
<java-to-jar srcdir="src/library" destjar="build/hamcrest-library-${version}.jar"
16+
classpath="build/hamcrest-api-${version}.jar"/>
17+
<java-to-jar srcdir="src/integration" destjar="build/hamcrest-integration-${version}.jar"
18+
classpath="build/hamcrest-api-${version}.jar"/>
19+
<java-to-jar srcdir="src/unit-test" destjar="build/hamcrest-unit-test-${version}.jar"
20+
classpath="build/hamcrest-api-${version}.jar;build/hamcrest-library-${version}.jar"/>
21+
</target>
22+
23+
<target name="test" description="Test project">
24+
<!-- TODO -->
25+
</target>
26+
27+
<target name="package" depends="build" description="Package for distribution">
28+
<zip zipfile="build/hamcrest-${version}.zip">
29+
<zipfileset dir="." prefix="hamcrest-${version}">
30+
<include name="src/**"/>
31+
<include name="lib/**"/>
32+
<include name="*.txt"/>
33+
<include name="build.xml"/>
34+
</zipfileset>
35+
<zipfileset dir="build" prefix="hamcrest-${version}">
36+
<include name="hamcrest-api-${version}.jar"/>
37+
<include name="hamcrest-library-${version}.jar"/>
38+
<include name="hamcrest-integration-${version}.jar"/>
39+
</zipfileset>
40+
</zip>
41+
</target>
42+
43+
<macrodef name="java-to-jar" description="Compile Java source and build a Jar">
44+
<attribute name="srcdir" description="Directory containg Java source"/>
45+
<attribute name="destjar" description="Path to Jar"/>
46+
<attribute name="classpath" description="Anything additional to add on the classpath" default=""/>
47+
<sequential>
48+
<mkdir dir="build/temp/@{destjar}.contents"/>
49+
<javac srcdir="@{srcdir}" destdir="build/temp/@{destjar}.contents" classpath="@{classpath}"/>
50+
<jar jarfile="@{destjar}">
51+
<fileset dir="build/temp/@{destjar}.contents"/>
52+
</jar>
53+
</sequential>
54+
</macrodef>
55+
56+
</project>

‎lib/junit-3.8.1.jar‎

118 KB
Binary file not shown.

‎src/api/org/hamcrest/Matcher.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Copyright (c) 2000-2006 hamcrest.org
2+
*/
3+
package org.hamcrest;
4+
5+
// TODO: Update JavaDoc to make better use of 'matcher' word.
6+
7+
/**
8+
* A matcher over acceptable values. A matcher should be able to describe itself to give feedback when it fails.
9+
*/
10+
public interface Matcher {
11+
/**
12+
* Evaluates the matcher for argument <var>o</var>.
13+
*
14+
* @param o the object against which the matcher is evaluated.
15+
* @return <code>true</code> if <var>o</var> matcher, otherwise <code>false</code>.
16+
*/
17+
boolean match(Object o);
18+
19+
/**
20+
* Appends the description of this object to the buffer.
21+
*
22+
* @param buffer The buffer that the description is appended to.
23+
*/
24+
void describeTo(StringBuffer buffer);
25+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Copyright (c) 2000-2006 hamcrest.org
2+
*/
3+
package org.hamcrest.junit;
4+
5+
import org.hamcrest.Matcher;
6+
import junit.framework.Assert;
7+
8+
public class MatcherAssert extends Assert {
9+
10+
public void assertThat(Object actual, Matcher matcher) {
11+
if (!matcher.match(actual)) {
12+
StringBuffer message = new StringBuffer("\nExpected: ");
13+
matcher.describeTo(message);
14+
message.append("\n got : ").append(actual).append('\n');
15+
fail(message.toString());
16+
}
17+
}
18+
19+
public void assertThat(boolean actual, Matcher matcher) {
20+
assertThat(actual ? Boolean.TRUE : Boolean.FALSE, matcher);
21+
}
22+
23+
public void assertThat(byte actual, Matcher matcher) {
24+
assertThat(new Byte(actual), matcher);
25+
}
26+
27+
public void assertThat(short actual, Matcher matcher) {
28+
assertThat(new Short(actual), matcher);
29+
}
30+
31+
public void assertThat(char actual, Matcher matcher) {
32+
assertThat(new Character(actual), matcher);
33+
}
34+
35+
public void assertThat(int actual, Matcher matcher) {
36+
assertThat(new Integer(actual), matcher);
37+
}
38+
39+
public void assertThat(long actual, Matcher matcher) {
40+
assertThat(new Long(actual), matcher);
41+
}
42+
43+
public void assertThat(float actual, Matcher matcher) {
44+
assertThat(new Float(actual), matcher);
45+
}
46+
47+
public void assertThat(double actual, Matcher matcher) {
48+
assertThat(new Double(actual), matcher);
49+
}
50+
51+
}

0 commit comments

Comments
 (0)