Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit e2fea79

Browse files
committed
Fixed intermittently failing tests based on JMockit which does not support parallel test execution.
(cherry picked from commit 97ea29e) Change-Id: Ie87cd6702e6de07ff329717e054e893ad13be2c3
1 parent fc3b58b commit e2fea79

File tree

3 files changed

+45
-38
lines changed

3 files changed

+45
-38
lines changed

core-client/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@
155155
</dependency>
156156

157157
<dependency>
158-
<groupId>org.jmockit</groupId>
159-
<artifactId>jmockit</artifactId>
158+
<groupId>org.mockito</groupId>
159+
<artifactId>mockito-all</artifactId>
160160
<scope>test</scope>
161161
</dependency>
162162
</dependencies>

core-client/src/test/java/org/glassfish/jersey/client/ClientRequestTest.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import java.io.IOException;
4343
import java.io.OutputStream;
4444
import java.lang.annotation.Annotation;
45-
import java.lang.reflect.Type;
4645
import java.net.URI;
4746

4847
import javax.ws.rs.core.GenericType;
@@ -57,27 +56,39 @@
5756

5857
import org.hamcrest.core.Is;
5958
import org.junit.Assert;
59+
import org.junit.Before;
6060
import org.junit.Test;
6161
import org.junit.runner.RunWith;
62+
import org.mockito.Mock;
63+
import org.mockito.Mockito;
64+
import org.mockito.MockitoAnnotations;
65+
import org.mockito.runners.MockitoJUnitRunner;
6266
import static org.junit.Assert.assertEquals;
6367
import static org.junit.Assert.assertFalse;
6468
import static org.junit.Assert.assertNull;
6569
import static org.junit.Assert.assertTrue;
6670
import static org.junit.Assert.fail;
67-
68-
import mockit.Mock;
69-
import mockit.MockUp;
70-
import mockit.Mocked;
71-
import mockit.integration.junit4.JMockit;
71+
import static org.mockito.Matchers.any;
72+
import static org.mockito.Matchers.same;
7273

7374
/**
7475
* {@code ClientRequest} unit tests.
7576
*
7677
* @author Marek Potociar (marek.potociar at oracle.com)
7778
*/
78-
@RunWith(JMockit.class)
79+
@RunWith(MockitoJUnitRunner.class)
7980
public class ClientRequestTest {
8081

82+
@Mock
83+
private MessageBodyWorkers workers;
84+
@Mock
85+
private GenericType<?> entityType;
86+
87+
@Before
88+
public void initMocks() {
89+
MockitoAnnotations.initMocks(this);
90+
}
91+
8192
/**
8293
* Test of resolving properties in the client request.
8394
*/
@@ -157,26 +168,27 @@ public void testResolveProperty() {
157168
assertEquals("value-request", request.resolveProperty("name", "value-default"));
158169
}
159170

160-
@Test
161-
public void testSSLExceptionHandling(@Mocked MessageBodyWorkers workers, @Mocked GenericType<?> entityType)
162-
throws Exception {
171+
private ClientRequest mockThrowing(Exception exception) throws IOException {
163172
JerseyClient client = new JerseyClientBuilder().build();
164173
final ClientRequest request = new ClientRequest(
165174
URI.create("http://example.org"),
166175
client.getConfiguration(),
167176
new MapPropertiesDelegate());
168177

178+
Mockito.doThrow(exception).when(workers)
179+
.writeTo(any(), same(entityType.getRawType()), same(entityType.getType()),
180+
Mockito.<Annotation[]>any(), Mockito.<MediaType>any(),
181+
Mockito.<MultivaluedMap<String, Object>>any(), Mockito.<PropertiesDelegate>any(),
182+
Mockito.<OutputStream>any(), Mockito.<Iterable<WriterInterceptor>>any());
183+
return request;
184+
}
185+
186+
@Test
187+
public void testSSLExceptionHandling()
188+
throws Exception {
169189
final IOException ioException = new IOException("Test");
170-
new MockUp<MessageBodyWorkers>(workers) {
171-
@Mock
172-
OutputStream writeTo(Object entity, Class<?> rawType, Type type, Annotation[] annotations,
173-
MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
174-
PropertiesDelegate propertiesDelegate, OutputStream entityStream,
175-
Iterable<WriterInterceptor> writerInterceptors)
176-
throws java.io.IOException, javax.ws.rs.WebApplicationException {
177-
throw ioException;
178-
}
179-
};
190+
191+
final ClientRequest request = mockThrowing(ioException);
180192

181193
try {
182194
request.doWriteEntity(workers, entityType);
@@ -186,26 +198,14 @@ OutputStream writeTo(Object entity, Class<?> rawType, Type type, Annotation[] an
186198
e, Is.is(ioException));
187199
}
188200
}
201+
189202
@Test
190-
public void testRuntimeExceptionBeingReThrown(@Mocked MessageBodyWorkers workers, @Mocked GenericType<?> entityType)
203+
public void testRuntimeExceptionBeingReThrown()
191204
throws Exception {
192-
JerseyClient client = new JerseyClientBuilder().build();
193-
final ClientRequest request = new ClientRequest(
194-
URI.create("http://example.org"),
195-
client.getConfiguration(),
196-
new MapPropertiesDelegate());
197205

198206
final RuntimeException runtimeException = new RuntimeException("Test");
199-
new MockUp<MessageBodyWorkers>(workers) {
200-
@Mock
201-
OutputStream writeTo(Object entity, Class<?> rawType, Type type, Annotation[] annotations,
202-
MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
203-
PropertiesDelegate propertiesDelegate, OutputStream entityStream,
204-
Iterable<WriterInterceptor> writerInterceptors)
205-
throws java.io.IOException, javax.ws.rs.WebApplicationException {
206-
throw runtimeException;
207-
}
208-
};
207+
208+
ClientRequest request = mockThrowing(runtimeException);
209209

210210
try {
211211
request.doWriteEntity(workers, entityType);

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,12 @@
17681768
<version>${jmockit.version}</version>
17691769
<scope>test</scope>
17701770
</dependency>
1771+
<dependency>
1772+
<groupId>org.mockito</groupId>
1773+
<artifactId>mockito-all</artifactId>
1774+
<version>${mockito.version}</version>
1775+
<scope>test</scope>
1776+
</dependency>
17711777
<dependency>
17721778
<groupId>xmlunit</groupId>
17731779
<artifactId>xmlunit</artifactId>
@@ -1894,5 +1900,6 @@
18941900
<weld.version>2.2.14.Final</weld.version>
18951901
<xerces.version>2.11.0</xerces.version>
18961902
<xmlunit.version>1.6</xmlunit.version>
1903+
<mockito.version>1.10.19</mockito.version>
18971904
</properties>
18981905
</project>

0 commit comments

Comments
 (0)