Skip to content

Commit f2966c7

Browse files
author
Thierry Boileau
committed
Clean unit tests
1 parent 4d1ba9b commit f2966c7

File tree

8 files changed

+50
-9
lines changed

8 files changed

+50
-9
lines changed

org.restlet/src/test/java/org/restlet/engine/connector/AsyncTestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ private void testCall(Context context, int count, Method method) throws Exceptio
101101

102102
@BeforeEach
103103
protected void setUpEach() throws Exception {
104+
Engine.clearThreadLocalVariables();
104105
Engine.register(true);
105106
// Create components
106107
clientComponent = new Component();
@@ -188,5 +189,6 @@ protected void tearDownEach() throws Exception {
188189
// Stop the components
189190
clientComponent.stop();
190191
originComponent.stop();
192+
Engine.clearThreadLocalVariables();
191193
}
192194
}

org.restlet/src/test/java/org/restlet/engine/connector/BaseConnectorsTestCase.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private void initEngine(HttpServer server, HttpClient client) {
113113
if (shouldDebug()) {
114114
Engine.setLogLevel(Level.FINE);
115115
}
116-
116+
Engine.clearThreadLocalVariables();
117117
Engine nre = Engine.register(false);
118118
nre.getRegisteredServers().add(server.serverHelper);
119119
nre.getRegisteredClients().add(client.clientHelper);
@@ -123,7 +123,8 @@ private void initEngine(HttpServer server, HttpClient client) {
123123

124124
private void resetEngine() {
125125
// Restore a clean engine
126-
org.restlet.engine.Engine.register();
126+
Engine.register();
127+
Engine.clearThreadLocalVariables();
127128
}
128129

129130
public enum HttpServer {

org.restlet/src/test/java/org/restlet/engine/connector/HttpTransportProtocolsTestCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public static void setup() {
8181
nre.getRegisteredClients().add(0, new HttpClientHelper(null));
8282
}
8383

84+
@BeforeAll
85+
public static void tearDown() {
86+
Engine.clearThreadLocalVariables();
87+
}
88+
8489
@Override
8590
Server newServer(String httpTransportProtocolOption) {
8691
final Context context = new Context();

org.restlet/src/test/java/org/restlet/engine/connector/ShutdownHookTestCase.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
import java.util.logging.Level;
3434
import java.util.logging.Logger;
3535

36+
import org.junit.jupiter.api.AfterEach;
3637
import org.junit.jupiter.api.BeforeAll;
38+
import org.junit.jupiter.api.BeforeEach;
3739
import org.junit.jupiter.api.Test;
3840
import org.restlet.Context;
3941
import org.restlet.Request;
@@ -50,9 +52,16 @@ public class ShutdownHookTestCase {
5052
private static final Logger LOGGER = Logger.getLogger("ShutdownHookTest");
5153
private static boolean shouldDebug = false;
5254

53-
@BeforeAll
54-
public static void setUp() {
55-
LOGGER.setLevel(Level.INFO);
55+
@BeforeEach
56+
public void setUp() {
57+
LOGGER.setLevel(Level.FINE);
58+
Engine.clearThreadLocalVariables();
59+
Engine.register(true);
60+
}
61+
62+
@AfterEach
63+
public void tearDown() {
64+
Engine.clearThreadLocalVariables();
5665
Engine.register(true);
5766
}
5867

@@ -78,7 +87,7 @@ public void whenServerIsNotHandlingRequestThenItStopsImmediately() throws Except
7887
*
7988
* This is done by making a request froze, then stopping the server, and checking that it didn't wait.
8089
*/
81-
// FIXME @Test
90+
@Test
8291
public void whenServerIsHandlingBlockingRequestThenItStopsImmediately() throws Exception {
8392
// Given a server resource that takes 1 min to send a response
8493
final Lock lock = new Lock("Server");
@@ -113,7 +122,7 @@ public void whenServerIsHandlingBlockingRequestThenItStopsImmediately() throws E
113122
*
114123
* This is done by making a request froze, then stopping the server, and checking that it waited the expected amount of time before shutting down.
115124
*/
116-
// FIXME @Test
125+
@Test
117126
public void whenServerIsHandlingBlockingRequestThenItGracefullyWaitsFor1SecondBeforeStopping() throws Exception {
118127
// Given a server resource that takes 1 min to send a response
119128
final Lock serverLock = new Lock("Server");
@@ -148,7 +157,7 @@ public void whenServerIsHandlingBlockingRequestThenItGracefullyWaitsFor1SecondBe
148157
*
149158
* This is done by making a request froze, then stopping the server, and checking that a new request is not taken into account.
150159
*/
151-
// FIXME @Test
160+
@Test
152161
public void whenServerIsHandlingBlockingRequestThenItRefusesNewRequest() throws Exception {
153162
// Given a server resource that takes 1 min to send a response
154163
final Lock lock = new Lock("Server");
@@ -185,7 +194,7 @@ public void whenServerIsHandlingBlockingRequestThenItRefusesNewRequest() throws
185194
*
186195
* This is done by making a request froze for a short amount of time, then stopping the server, and checking that the request has been handled.
187196
*/
188-
// FIXME @Test
197+
@Test
189198
public void whenServerIsHandlingLongRequestThenRequestIsHandledCorrectlyBeforeStopping() throws Exception {
190199
// Given a server resource that takes 1 sec to send a response
191200
final Lock lock = new Lock("Server");

org.restlet/src/test/java/org/restlet/engine/connector/SslBaseConnectorsTestCase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.restlet.Server;
2525
import org.restlet.data.Parameter;
2626
import org.restlet.data.Protocol;
27+
import org.restlet.engine.Engine;
2728
import org.restlet.engine.io.IoUtils;
2829
import org.restlet.util.Series;
2930

@@ -45,6 +46,8 @@ public abstract class SslBaseConnectorsTestCase extends BaseConnectorsTestCase {
4546

4647
@BeforeAll
4748
public static void globalSetUp() throws IOException {
49+
Engine.clearThreadLocalVariables();
50+
Engine.register();
4851
testKeystoreFile = Files
4952
.createTempFile("sslBaseConnectorsTest", KEYSTORE_FILE_NAME)
5053
.toFile();
@@ -114,6 +117,7 @@ protected static void tearDown() {
114117
testKeystoreFile.delete();
115118

116119
// Restore a clean engine
120+
Engine.clearThreadLocalVariables();
117121
org.restlet.engine.Engine.register();
118122
}
119123

org.restlet/src/test/java/org/restlet/representation/DigesterRepresentationTestCase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class DigesterRepresentationTestCase {
3737

3838
@BeforeEach
3939
protected void setUpEach() throws Exception {
40+
Engine.clearThreadLocalVariables();
4041
Engine.register();
4142
component = new Component();
4243
final Server server = component.getServers().add(Protocol.HTTP, 0);
@@ -47,6 +48,8 @@ protected void setUpEach() throws Exception {
4748

4849
@AfterEach
4950
protected void tearDownEach() throws Exception {
51+
Engine.clearThreadLocalVariables();
52+
Engine.register();
5053
component.stop();
5154
component = null;
5255
}

org.restlet/src/test/java/org/restlet/representation/FileRepresentationTestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class FileRepresentationTestCase {
4949

5050
@BeforeEach
5151
protected void setUpEach() throws Exception {
52+
Engine.clearThreadLocalVariables();
5253
Engine.register(true);
5354
component = new Component();
5455
Server server = component.getServers().add(Protocol.HTTP, 0);
@@ -62,6 +63,7 @@ protected void setUpEach() throws Exception {
6263

6364
@AfterEach
6465
protected void tearDownEach() throws Exception {
66+
Engine.clearThreadLocalVariables();
6567
component.stop();
6668
component = null;
6769
}

org.restlet/src/test/java/org/restlet/routing/RedirectTestCase.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99

1010
package org.restlet.routing;
1111

12+
import org.junit.jupiter.api.AfterEach;
13+
import org.junit.jupiter.api.BeforeEach;
1214
import org.junit.jupiter.api.Test;
1315
import org.restlet.*;
1416
import org.restlet.data.MediaType;
1517
import org.restlet.data.Method;
1618
import org.restlet.data.Protocol;
19+
import org.restlet.engine.Engine;
1720
import org.restlet.representation.StringRepresentation;
1821

1922
import static java.lang.String.format;
@@ -36,6 +39,18 @@ private void testCall(Context context, Method method, String uri)
3639
response.getEntity().write(System.out);
3740
}
3841

42+
@BeforeEach
43+
public void setUp() {
44+
Engine.clearThreadLocalVariables();
45+
Engine.register();
46+
}
47+
48+
@AfterEach
49+
public void tearDown() {
50+
Engine.clearThreadLocalVariables();
51+
Engine.register();
52+
}
53+
3954
/**
4055
* Tests the cookies parsing.
4156
*/

0 commit comments

Comments
 (0)