Skip to content

Commit 305cc4b

Browse files
author
Matthew Gilliard
committed
switched easymock -> mockito
1 parent 0f6fba1 commit 305cc4b

5 files changed

Lines changed: 111 additions & 169 deletions

File tree

pom.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23

34
<modelVersion>4.0.0</modelVersion>
45

@@ -176,9 +177,10 @@
176177
</dependency>
177178

178179
<dependency>
179-
<groupId>org.easymock</groupId>
180-
<artifactId>easymock</artifactId>
181-
<version>3.0</version>
180+
<groupId>org.mockito</groupId>
181+
<artifactId>mockito-core</artifactId>
182+
<version>1.8.1</version>
183+
<scope>test</scope>
182184
</dependency>
183185

184186
<dependency>

rest-client-driver/pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34

45
<artifactId>rest-client-driver</artifactId>
@@ -20,8 +21,8 @@
2021
</dependency>
2122

2223
<dependency>
23-
<groupId>org.easymock</groupId>
24-
<artifactId>easymock</artifactId>
24+
<groupId>org.mockito</groupId>
25+
<artifactId>mockito-core</artifactId>
2526
<scope>test</scope>
2627
</dependency>
2728

rest-client-driver/src/test/java/com/github/restdriver/clientdriver/clientdriver/unit/BenchHandlerTest.java

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,32 @@
3030
import com.github.restdriver.clientdriver.jetty.DefaultClientDriverJettyHandler;
3131
import junit.framework.Assert;
3232

33-
import org.easymock.EasyMock;
3433
import org.eclipse.jetty.server.Request;
35-
import org.junit.After;
3634
import org.junit.Before;
3735
import org.junit.Test;
3836

3937
import com.github.restdriver.clientdriver.exception.ClientDriverInternalException;
4038

39+
import static org.mockito.Mockito.mock;
40+
import static org.mockito.Mockito.when;
41+
4142
public class BenchHandlerTest {
4243

4344
private DefaultClientDriverJettyHandler sut;
4445
private RequestMatcher mockRequestMatcher;
4546

4647
@Before
4748
public void before() {
48-
mockRequestMatcher = EasyMock.createMock(RequestMatcher.class);
49+
mockRequestMatcher = mock(RequestMatcher.class);
4950
sut = new DefaultClientDriverJettyHandler(mockRequestMatcher);
5051
}
5152

52-
@After
53-
public void after() {
54-
EasyMock.verify(mockRequestMatcher);
55-
}
56-
5753
/**
5854
* with no expectations set, and no requests made, the handler does not report any errors
5955
*/
6056
@Test
6157
public void testMinimalHandler() {
6258

63-
EasyMock.replay(mockRequestMatcher);
64-
6559
sut.checkForUnexpectedRequests();
6660
sut.checkForUnmatchedExpectations();
6761

@@ -75,8 +69,6 @@ public void testUnmetExpectation() {
7569

7670
sut.addExpectation(new ClientDriverRequest("hmm"), new ClientDriverResponse("mmm"));
7771

78-
EasyMock.replay(mockRequestMatcher);
79-
8072
sut.checkForUnexpectedRequests();
8173

8274
try {
@@ -94,16 +86,12 @@ public void testUnmetExpectation() {
9486
@Test
9587
public void testUnexpectedRequest() throws IOException, ServletException {
9688

97-
Request mockRequest = EasyMock.createMock(Request.class);
98-
HttpServletRequest mockHttpRequest = EasyMock.createMock(HttpServletRequest.class);
99-
HttpServletResponse mockHttpResponse = EasyMock.createMock(HttpServletResponse.class);
89+
Request mockRequest = mock(Request.class);
90+
HttpServletRequest mockHttpRequest = mock(HttpServletRequest.class);
91+
HttpServletResponse mockHttpResponse = mock(HttpServletResponse.class);
10092

101-
EasyMock.expect(mockHttpRequest.getPathInfo()).andReturn("yarr");
102-
EasyMock.expect(mockHttpRequest.getQueryString()).andReturn("gooo=gredge");
103-
104-
EasyMock.replay(mockHttpRequest);
105-
EasyMock.replay(mockHttpResponse);
106-
EasyMock.replay(mockRequestMatcher);
93+
when(mockHttpRequest.getPathInfo()).thenReturn("yarr");
94+
when(mockHttpRequest.getQueryString()).thenReturn("gooo=gredge");
10795

10896
try {
10997
sut.handle("", mockRequest, mockHttpRequest, mockHttpResponse);
@@ -112,9 +100,6 @@ public void testUnexpectedRequest() throws IOException, ServletException {
112100
Assert.assertEquals("Unexpected request: yarr?gooo=gredge", bre.getMessage());
113101
}
114102

115-
EasyMock.verify(mockHttpRequest);
116-
EasyMock.verify(mockHttpResponse);
117-
118103
try {
119104
sut.checkForUnexpectedRequests();
120105
Assert.fail();
@@ -130,34 +115,29 @@ public void testUnexpectedRequest() throws IOException, ServletException {
130115
@Test
131116
public void testExpectedRequest() throws IOException, ServletException {
132117

133-
Request mockRequest = EasyMock.createMock(Request.class);
118+
Request mockRequest = mock(Request.class);
134119
HttpServletRequest mockHttpRequest = new Request();
135-
HttpServletResponse mockHttpResponse = EasyMock.createMock(HttpServletResponse.class);
120+
HttpServletResponse mockHttpResponse = mock(HttpServletResponse.class);
136121

137122
ClientDriverRequest realRequest = new ClientDriverRequest("yarr").withParam("gooo", "gredge");
138123
ClientDriverResponse realResponse = new ClientDriverResponse("lovely").withStatus(404).withContentType("fhieow")
139124
.withHeader("hhh", "JJJ");
140125

141-
EasyMock.expect(mockRequestMatcher.isMatch(mockHttpRequest, realRequest)).andReturn(true);
126+
when(mockRequestMatcher.isMatch(mockHttpRequest, realRequest)).thenReturn(true);
142127

143128
mockHttpResponse.setContentType("fhieow");
144129
mockHttpResponse.setStatus(404);
145130

146131
ByteArrayOutputStream baos = new ByteArrayOutputStream();
147132
PrintWriter printWriter = new PrintWriter(baos);
148133

149-
EasyMock.expect(mockHttpResponse.getWriter()).andReturn(printWriter);
134+
when(mockHttpResponse.getWriter()).thenReturn(printWriter);
150135
mockHttpResponse.setHeader("hhh", "JJJ");
151136

152-
EasyMock.replay(mockHttpResponse);
153-
EasyMock.replay(mockRequestMatcher);
154-
155137
sut.addExpectation(realRequest, realResponse);
156138

157139
sut.getJettyHandler().handle("", mockRequest, mockHttpRequest, mockHttpResponse);
158140

159-
EasyMock.verify(mockHttpResponse);
160-
161141
printWriter.close();
162142
Assert.assertEquals("lovely", new String(baos.toByteArray()));
163143

0 commit comments

Comments
 (0)