Skip to content

Commit c954f88

Browse files
author
joeretro
committed
Created examples of using Hamcrest across different combinations of assertThat, jMock and EasyMock.
Also showed how it would look with different frameworks: JUnit 3, JUnit 4 and TestNG. Really this is focussing on ideal end usage and is paving the way for some acceptance tests. Note that I have created some placeholder classes for Matchers that don't contain the real methods yet. Things learned: * Java 5 makes the whole thing much cleaner (static imports, generics, auto-boxing and var-args). Trying to support earlier Java's will be tricky without degrading the Java 5 version. * The main class with static helpers method (for the sugar) will most likely need a separate version for assertThat, jMock and EasyMock as the methods need to return a different type. The methods themselves will be duplicated. Perhaps this should be code generated? * jMock is hard to use outside of JUnit 3. * Combining assertThat and EasyMock is awkward because the EasyMock will be recording the matchers, which could confuse it (possibly?).
1 parent c2aa5cb commit c954f88

32 files changed

Lines changed: 1314 additions & 77 deletions

‎TODO.txt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@
3131

3232
* ComparisonMatcher (See NMock2)
3333

34-
* Sugar for new matchers
34+
* Sugar for new matchers
35+
36+
* NOT_NULL, IS_ANYTHING, etc -> notNull(), isAnything(), etc.

‎build.xml‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
<java-to-jar srcdir="src/library" destjar="build/hamcrest-library-${version}.jar"
1616
classpath="build/hamcrest-api-${version}.jar"/>
1717
<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"
2018
classpath="build/hamcrest-api-${version}.jar;build/hamcrest-library-${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;build/hamcrest-integration-${version}.jar"/>
21+
<java-to-jar srcdir="src/examples" destjar="build/hamcrest-examples-${version}.jar"
22+
classpath="build/hamcrest-api-${version}.jar;build/hamcrest-library-${version}.jar;build/hamcrest-integration-${version}.jar"/>
2123
</target>
2224

2325
<target name="test" description="Test project">
@@ -45,10 +47,20 @@
4547
<attribute name="destjar" description="Path to Jar"/>
4648
<attribute name="classpath" description="Anything additional to add on the classpath" default=""/>
4749
<sequential>
50+
<echo message="* Java source (@{srcdir}) -> Jar (@{destjar})"/>
4851
<mkdir dir="build/temp/@{destjar}.contents"/>
49-
<javac srcdir="@{srcdir}" destdir="build/temp/@{destjar}.contents" classpath="@{classpath}"/>
52+
<javac srcdir="@{srcdir}" destdir="build/temp/@{destjar}.contents">
53+
<classpath>
54+
<fileset dir="lib/integration">
55+
<include name="*.jar"/>
56+
</fileset>
57+
<pathelement path="@{classpath}"/>
58+
</classpath>
59+
</javac>
5060
<jar jarfile="@{destjar}">
5161
<fileset dir="build/temp/@{destjar}.contents"/>
62+
<fileset dir="@{srcdir}"/>
63+
<!-- Also put Java source in Jar for user's convenience. -->
5264
</jar>
5365
</sequential>
5466
</macrodef>

‎lib/integration/easymock-2.2.jar‎

61.2 KB
Binary file not shown.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="iso-8859-1"?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4+
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
7+
<title>EasyMock License</title>
8+
<link rel="stylesheet" href="easymock.css" />
9+
</head>
10+
11+
<body><div class="bodywidth">
12+
13+
<h2>
14+
EasyMock 2 License (MIT License)
15+
</h2>
16+
17+
<em>Copyright (c) 2001-2006 <a href="http://www.offis.de">OFFIS</a>, <a href="http://www.tammofreese.de">Tammo Freese</a>.</em>
18+
19+
<p>
20+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
21+
</p>
22+
<p>
23+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
24+
</p>
25+
<p>
26+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27+
</p>
28+
29+
</div>
30+
</body>
31+
</html>
32+
33+

‎lib/integration/jmock-1.10RC1.jar‎

98.1 KB
Binary file not shown.

‎lib/integration/jmock-license.txt‎

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

‎lib/integration/junit-4.0.jar‎

103 KB
Binary file not shown.

0 commit comments

Comments
 (0)