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

Commit 97ea29e

Browse files
committed
Fixed intermittently failing tests based on JMockit which does not support parallel test execution.
Change-Id: Ic38a0f37c494e1b9dd60975116ef048c44c84ff4
1 parent 3646d5a commit 97ea29e

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
lines changed

core-client/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
55
6-
Copyright (c) 2011-2015 Oracle and/or its affiliates. All rights reserved.
6+
Copyright (c) 2011-2016 Oracle and/or its affiliates. All rights reserved.
77
88
The contents of this file are subject to the terms of either the GNU
99
General Public License Version 2 only ("GPL") or the Common Development
@@ -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
@@ -1771,6 +1771,12 @@
17711771
<version>${jmockit.version}</version>
17721772
<scope>test</scope>
17731773
</dependency>
1774+
<dependency>
1775+
<groupId>org.mockito</groupId>
1776+
<artifactId>mockito-all</artifactId>
1777+
<version>${mockito.version}</version>
1778+
<scope>test</scope>
1779+
</dependency>
17741780
<dependency>
17751781
<groupId>xmlunit</groupId>
17761782
<artifactId>xmlunit</artifactId>
@@ -1899,5 +1905,6 @@
18991905
<weld.version>2.2.14.Final</weld.version>
19001906
<xerces.version>2.11.0</xerces.version>
19011907
<xmlunit.version>1.6</xmlunit.version>
1908+
<mockito.version>1.10.19</mockito.version>
19021909
</properties>
19031910
</project>

0 commit comments

Comments
 (0)