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

Lines changed: 79 additions & 74 deletions

‎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+
}

0 commit comments

Comments
 (0)