Skip to content

Commit 685e7e1

Browse files
author
joeretro
committed
Changed class names (EasyMock -> EasyMock2, JMock -> JMock1) for clarity.
1 parent fc1ec99 commit 685e7e1

15 files changed

+79
-74
lines changed

src/examples/org/hamcrest/examples/junit3/ExampleWithAssertThat.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import junit.framework.TestCase;
44
import static org.hamcrest.MatcherAssert.assertThat;
5-
import static org.hamcrest.Matchers.isTwoXs;
5+
import static org.hamcrest.Matchers.equalTo;
66
import static org.hamcrest.core.IsNot.not;
77
import static org.hamcrest.text.StringContains.containsString;
88

@@ -15,8 +15,8 @@
1515
public class ExampleWithAssertThat extends TestCase {
1616

1717
public void testUsingAssertThat() {
18-
assertThat("xx", isTwoXs());
19-
assertThat("yy", not(isTwoXs()));
18+
assertThat("xx", equalTo("xx"));
19+
assertThat("yy", not(equalTo("xx")));
2020
assertThat("i like cheese", containsString("cheese"));
2121
}
2222

src/examples/org/hamcrest/examples/junit3/ExampleWithEasyMock.java renamed to src/examples/org/hamcrest/examples/junit3/ExampleWithEasyMock2.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.hamcrest.examples.junit3;
22

33
import static org.easymock.EasyMock.*;
4-
import static org.hamcrest.EasyMockMatchers.*;
4+
import static org.hamcrest.EasyMock2Matchers.*;
55
import junit.framework.TestCase;
66

77
/**
@@ -10,7 +10,7 @@
1010
*
1111
* @author Joe Walnes
1212
*/
13-
public class ExampleWithEasyMock extends TestCase {
13+
public class ExampleWithEasyMock2 extends TestCase {
1414

1515
/* EasyMock (2) specific notes:
1616
*
@@ -43,8 +43,8 @@ public static interface AnInterface {
4343
* This examples shows using a mock with a standard EasyMock2 matcher.
4444
* Hamcrest is not used here.
4545
*/
46-
public void testUsingAJMockConstraint() {
47-
mock.doStuff(startsWith("i like"));
46+
public void testUsingAnEasyMockMatcher() {
47+
mock.doStuff(eq("i like cheese and stuff"));
4848
replay(mock);
4949
mock.doStuff("i like cheese and stuff");
5050
verify(mock);
@@ -55,7 +55,7 @@ public void testUsingAJMockConstraint() {
5555
* to jMock.
5656
*/
5757
public void testUsingAHamcrestMatcher() {
58-
mock.doStuff(isTwoXs());
58+
mock.doStuff(equalTo("xx"));
5959
replay(mock);
6060
mock.doStuff("xx");
6161
verify(mock);
@@ -67,8 +67,8 @@ public void testUsingAHamcrestMatcher() {
6767
*/
6868
public void testUsingAssertThat() {
6969
// TODO(joe): This is a bit tricker with EasyMock.
70-
//assertThat("xx", isTwoXs());
71-
//assertThat("yy", not(isTwoXs()));
70+
//assertThat("xx", equal("xx"));
71+
//assertThat("yy", not(equal("xx")));
7272
//assertThat("i like cheese", startsWith("i like"));
7373
}
7474

src/examples/org/hamcrest/examples/junit3/ExampleWithJMock.java renamed to src/examples/org/hamcrest/examples/junit3/ExampleWithJMock1.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.hamcrest.examples.junit3;
22

3-
import static org.hamcrest.JMockMatchers.isTwoXs;
3+
import static org.hamcrest.JMock1Matchers.equalTo;
44
import org.jmock.Mock;
55
import org.jmock.MockObjectTestCase;
66

@@ -9,13 +9,16 @@
99
*
1010
* @author Joe Walnes
1111
*/
12-
public class ExampleWithJMock extends MockObjectTestCase {
12+
public class ExampleWithJMock1 extends MockObjectTestCase {
1313

1414
/* jMock specific notes:
1515
*
1616
* Important terminology:
1717
* What jMock calls 'Constraints', Hamcrest calls 'Matchers'.
1818
*
19+
* Note: This is only valid for jMock1. jMock2 supports Hamcrest out
20+
* of the box.
21+
*
1922
* The class extends org.jmock.MockObjectTestCase as usual.
2023
* This provides:
2124
* - The mock() methods and syntactic sugar for setting up mocks.
@@ -57,7 +60,7 @@ public void testUsingAJMockConstraint() {
5760
*/
5861
public void testUsingAHamcrestMatcher() {
5962
mock.expects(atLeastOnce()).method("doStuff")
60-
.with(isTwoXs());
63+
.with(equalTo("xx"));
6164

6265
anInterface.doStuff("xx");
6366
}
@@ -68,8 +71,8 @@ public void testUsingAHamcrestMatcher() {
6871
*/
6972
public void testUsingAssertThat() {
7073
assertThat("i like cheese", stringContains("cheese")); // jMock Constraint.
71-
assertThat("xx", isTwoXs()); // Hamcrest Matcher.
72-
assertThat("yy", not(isTwoXs())); // Mixture of both.
74+
assertThat("xx", equalTo("xx")); // Hamcrest Matcher.
75+
assertThat("yy", not(equalTo("xx"))); // Mixture of both.
7376
}
7477

7578
}

src/examples/org/hamcrest/examples/junit4/ExampleWithAssertThat.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.hamcrest.examples.junit4;
22

33
import static org.hamcrest.MatcherAssert.assertThat;
4-
import static org.hamcrest.Matchers.isTwoXs;
4+
import static org.hamcrest.Matchers.equalTo;
55
import static org.hamcrest.core.IsNot.not;
66
import static org.hamcrest.text.StringContains.containsString;
77
import org.junit.Test;
@@ -16,8 +16,8 @@ public class ExampleWithAssertThat {
1616

1717
@Test
1818
public void usingAssertThat() {
19-
assertThat("xx", isTwoXs());
20-
assertThat("yy", not(isTwoXs()));
19+
assertThat("xx", equalTo("xx"));
20+
assertThat("yy", not(equalTo("xx")));
2121
assertThat("i like cheese", containsString("cheese"));
2222
}
2323

src/examples/org/hamcrest/examples/junit4/ExampleWithEasyMock.java renamed to src/examples/org/hamcrest/examples/junit4/ExampleWithEasyMock2.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.hamcrest.examples.junit4;
22

33
import static org.easymock.EasyMock.*;
4-
import static org.hamcrest.EasyMockMatchers.*;
4+
import static org.hamcrest.EasyMock2Matchers.*;
55
import org.junit.Test;
66

77
/**
@@ -10,7 +10,7 @@
1010
*
1111
* @author Joe Walnes
1212
*/
13-
public class ExampleWithEasyMock {
13+
public class ExampleWithEasyMock2 {
1414

1515
/* EasyMock (2) specific notes:
1616
*
@@ -44,8 +44,8 @@ public static interface AnInterface {
4444
* Hamcrest is not used here.
4545
*/
4646
@Test
47-
public void usingAJMockConstraint() {
48-
mock.doStuff(startsWith("i like"));
47+
public void usingAnEasyMockMatcher() {
48+
mock.doStuff(eq("i like cheese and stuff"));
4949
replay(mock);
5050
mock.doStuff("i like cheese and stuff");
5151
verify(mock);
@@ -57,7 +57,7 @@ public void usingAJMockConstraint() {
5757
*/
5858
@Test
5959
public void usingAHamcrestMatcher() {
60-
mock.doStuff(isTwoXs());
60+
mock.doStuff(equalTo("xx"));
6161
replay(mock);
6262
mock.doStuff("xx");
6363
verify(mock);
@@ -79,6 +79,6 @@ public void usingAssertThat() {
7979
* Allow JUnit 4 test to be run under JUnit 3.
8080
*/
8181
public static junit.framework.Test suite() {
82-
return new junit.framework.JUnit4TestAdapter(ExampleWithEasyMock.class);
82+
return new junit.framework.JUnit4TestAdapter(ExampleWithEasyMock2.class);
8383
}
8484
}

src/examples/org/hamcrest/examples/testng/ExampleWithAssertThat.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.hamcrest.examples.testng;
22

33
import static org.hamcrest.MatcherAssert.assertThat;
4-
import static org.hamcrest.Matchers.isTwoXs;
4+
import static org.hamcrest.Matchers.equalTo;
55
import static org.hamcrest.core.IsNot.not;
66
import static org.hamcrest.text.StringContains.containsString;
77
import org.testng.annotations.Test;
@@ -17,8 +17,8 @@ public class ExampleWithAssertThat {
1717

1818
@Test
1919
public void usingAssertThat() {
20-
assertThat("xx", isTwoXs());
21-
assertThat("yy", not(isTwoXs()));
20+
assertThat("xx", equalTo("xx"));
21+
assertThat("yy", not(equalTo("xx")));
2222
assertThat("i like cheese", containsString("cheese"));
2323
}
2424

src/examples/org/hamcrest/examples/testng/ExampleWithEasyMock.java renamed to src/examples/org/hamcrest/examples/testng/ExampleWithEasyMock2.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.hamcrest.examples.testng;
22

3-
import static org.hamcrest.EasyMockMatchers.*;
3+
import static org.hamcrest.EasyMock2Matchers.*;
44
import static org.easymock.EasyMock.*;
55
import org.testng.annotations.Test;
66
import org.testng.annotations.Configuration;
@@ -12,7 +12,7 @@
1212
* @author Joe Walnes
1313
*/
1414
@Test
15-
public class ExampleWithEasyMock {
15+
public class ExampleWithEasyMock2 {
1616

1717
/* EasyMock (2) specific notes:
1818
*
@@ -51,8 +51,8 @@ public void setUpMock() {
5151
* Hamcrest is not used here.
5252
*/
5353
@Test
54-
public void usingAJMockConstraint() {
55-
mock.doStuff(startsWith("i like"));
54+
public void usingAnEasyMockMatcher() {
55+
mock.doStuff(eq("i like cheese and stuff"));
5656
replay(mock);
5757
mock.doStuff("i like cheese and stuff");
5858
verify(mock);
@@ -64,7 +64,7 @@ public void usingAJMockConstraint() {
6464
*/
6565
@Test
6666
public void usingAHamcrestMatcher() {
67-
mock.doStuff(isTwoXs());
67+
mock.doStuff(equalTo("xx"));
6868
replay(mock);
6969
mock.doStuff("xx");
7070
verify(mock);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.hamcrest;
2+
3+
import org.hamcrest.integration.EasyMock2Adapter;
4+
5+
/**
6+
*
7+
* @author Joe Walnes
8+
*/
9+
public class EasyMock2Matchers {
10+
11+
public static String equalTo(String string) {
12+
EasyMock2Adapter.adapt(Matchers.equalTo(string));
13+
return null;
14+
}
15+
16+
}

src/integration/org/hamcrest/EasyMockMatchers.java

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.hamcrest;
2+
3+
import org.hamcrest.integration.JMock1Adapter;
4+
import org.jmock.core.Constraint;
5+
6+
public class JMock1Matchers {
7+
8+
public static Constraint equalTo(String string) {
9+
return JMock1Adapter.adapt(Matchers.equalTo(string));
10+
}
11+
}

src/integration/org/hamcrest/JMockMatchers.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/integration/org/hamcrest/integration/EasyMockAdapter.java renamed to src/integration/org/hamcrest/integration/EasyMock2Adapter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @author Joe Walnes
1313
*/
14-
public class EasyMockAdapter implements IArgumentMatcher {
14+
public class EasyMock2Adapter implements IArgumentMatcher {
1515

1616
/**
1717
* Convenience factory method that will adapt a
@@ -20,14 +20,14 @@ public class EasyMockAdapter implements IArgumentMatcher {
2020
* report it to EasyMock so it can be kept track of.
2121
*/
2222
public static IArgumentMatcher adapt(Matcher matcher) {
23-
EasyMockAdapter easyMockMatcher = new EasyMockAdapter(matcher);
24-
EasyMock.reportMatcher(easyMockMatcher);
25-
return easyMockMatcher;
23+
EasyMock2Adapter easyMock2Matcher = new EasyMock2Adapter(matcher);
24+
EasyMock.reportMatcher(easyMock2Matcher);
25+
return easyMock2Matcher;
2626
}
2727

2828
private final Matcher hamcrestMatcher;
2929

30-
public EasyMockAdapter(Matcher matcher) {
30+
public EasyMock2Adapter(Matcher matcher) {
3131
this.hamcrestMatcher = matcher;
3232
}
3333

src/integration/org/hamcrest/integration/JMockAdapter.java renamed to src/integration/org/hamcrest/integration/JMock1Adapter.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,26 @@
66

77
/**
88
* An adapter to allowing a Hamcrest {@link org.hamcrest.Matcher}
9-
* to act as an jMock {@link org.jmock.core.Constraint}.
9+
* to act as an jMock1 {@link org.jmock.core.Constraint}.
10+
* Note, this is not necessary for jMock2 as it supports Hamcrest
11+
* out of the box.
1012
*
1113
* @author Joe Walnes
1214
*/
13-
public class JMockAdapter implements Constraint {
15+
public class JMock1Adapter implements Constraint {
1416

1517
/**
1618
* Convenience factory method that will adapt a
1719
* Hamcrest {@link org.hamcrest.Matcher} to act as an
1820
* jMock {@link org.jmock.core.Constraint}.
1921
*/
2022
public static Constraint adapt(Matcher matcher) {
21-
return new JMockAdapter(matcher);
23+
return new JMock1Adapter(matcher);
2224
}
2325

2426
private final Matcher hamcrestMatcher;
2527

26-
public JMockAdapter(Matcher matcher) {
28+
public JMock1Adapter(Matcher matcher) {
2729
this.hamcrestMatcher = matcher;
2830
}
2931

src/unit-test/org/hamcrest/integration/EasyMockAdapterTest.java renamed to src/unit-test/org/hamcrest/integration/EasyMock2AdapterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
import org.hamcrest.Description;
77
import static org.hamcrest.core.IsEqual.equalTo;
88

9-
public class EasyMockAdapterTest extends TestCase {
9+
public class EasyMock2AdapterTest extends TestCase {
1010

1111
public static interface InterfaceToMock {
1212
void doStuff(String name, int number);
1313
}
1414

1515
public void testAdaptsHamcrestMatcherToEasyMockArgumentsMatcher() {
16-
IArgumentMatcher easyMockMatcher = new EasyMockAdapter(equalTo("expected"));
16+
IArgumentMatcher easyMockMatcher = new EasyMock2Adapter(equalTo("expected"));
1717
assertTrue("Should have matched", easyMockMatcher.matches("expected"));
1818
assertFalse("Should not have matched", easyMockMatcher.matches("unexpected"));
1919
}
2020

2121
public void testDelegatesDescriptionToUnderlyingMatcher() {
22-
IArgumentMatcher easyMockMatcher = new EasyMockAdapter(new BaseMatcher() {
22+
IArgumentMatcher easyMockMatcher = new EasyMock2Adapter(new BaseMatcher() {
2323
public boolean matches(Object o) {
2424
return false;
2525
}

0 commit comments

Comments
 (0)