Skip to content

Commit

Permalink
Merge pull request #3882 from Dkafetzis/RESTEASY-3415
Browse files Browse the repository at this point in the history
[RESTEASY-3415] Migrate the resteasy-rxjava2 module to JUnit 5
  • Loading branch information
jamezp committed Oct 31, 2023
2 parents 4a49832 + 1f09ad9 commit b376d62
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 44 deletions.
4 changes: 2 additions & 2 deletions resteasy-rxjava2/pom.xml
Expand Up @@ -50,8 +50,8 @@

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
@@ -1,8 +1,6 @@
package org.jboss.resteasy.rxjava2;

import static org.jboss.resteasy.test.TestPortProvider.generateURL;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import java.util.Set;
import java.util.TreeSet;
Expand All @@ -19,12 +17,12 @@
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.plugins.server.netty.NettyJaxrsServer;
import org.jboss.resteasy.test.TestPortProvider;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import io.reactivex.Flowable;
import io.reactivex.Observable;
Expand All @@ -37,7 +35,7 @@ public class RxTest {
private static AtomicReference<Object> value = new AtomicReference<Object>();
private static final Logger LOG = Logger.getLogger(NettyJaxrsServer.class);

@BeforeClass
@BeforeAll
public static void beforeClass() throws Exception {
server = new NettyJaxrsServer();
server.setPort(TestPortProvider.getPort());
Expand All @@ -49,15 +47,15 @@ public static void beforeClass() throws Exception {
server.start();
}

@AfterClass
@AfterAll
public static void afterClass() throws Exception {
server.stop();
server = null;
}

private ResteasyClient client;

@Before
@BeforeEach
public void before() {
client = ((ResteasyClientBuilder) ClientBuilder.newBuilder())
.readTimeout(5, TimeUnit.SECONDS)
Expand All @@ -68,7 +66,7 @@ public void before() {
latch = new CountDownLatch(1);
}

@After
@AfterEach
public void after() {
client.close();
}
Expand All @@ -81,7 +79,7 @@ public void testSingle() throws Exception {
latch.countDown();
});
latch.await(5, TimeUnit.SECONDS);
assertEquals("got it", value.get());
Assertions.assertEquals("got it", value.get());
}

@Test
Expand All @@ -92,7 +90,7 @@ public void testSingleContext() throws Exception {
latch.countDown();
});
latch.await(5, TimeUnit.SECONDS);
assertEquals("got it", value.get());
Assertions.assertEquals("got it", value.get());
}

@Test
Expand All @@ -106,7 +104,7 @@ public void testObservable() throws Exception {
(Throwable t) -> LOG.error(t.getMessage(), t),
() -> latch.countDown());
latch.await(5, TimeUnit.SECONDS);
assertArrayEquals(new String[] { "one", "two" }, data.toArray());
Assertions.assertArrayEquals(new String[] { "one", "two" }, data.toArray());
}

@Test
Expand All @@ -121,7 +119,7 @@ public void testObservableContext() throws Exception {
(Throwable t) -> LOG.error(t.getMessage(), t),
() -> latch.countDown());
latch.await(5, TimeUnit.SECONDS);
assertArrayEquals(new String[] { "one", "two" }, data.toArray());
Assertions.assertArrayEquals(new String[] { "one", "two" }, data.toArray());
}

@Test
Expand All @@ -135,7 +133,7 @@ public void testFlowable() throws Exception {
(Throwable t) -> LOG.error(t.getMessage(), t),
() -> latch.countDown());
latch.await(5, TimeUnit.SECONDS);
assertArrayEquals(new String[] { "one", "two" }, data.toArray());
Assertions.assertArrayEquals(new String[] { "one", "two" }, data.toArray());
}

@Test
Expand All @@ -152,24 +150,24 @@ public void testFlowablecontext() throws Exception {
LOG.info("onComplete()");
});
latch.await(5, TimeUnit.SECONDS);
assertArrayEquals(new String[] { "one", "two" }, data.toArray());
Assertions.assertArrayEquals(new String[] { "one", "two" }, data.toArray());
}

// @Test
public void testChunked() throws Exception {
Invocation.Builder request = client.target(generateURL("/chunked")).request();
Response response = request.get();
String entity = response.readEntity(String.class);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals("onetwo", entity);
Assertions.assertEquals(200, response.getStatus());
Assertions.assertEquals("onetwo", entity);
}

@Test
public void testInjection() {
Integer data = client.target(generateURL("/injection")).request().get(Integer.class);
assertEquals((Integer) 42, data);
Assertions.assertEquals((Integer) 42, data);

data = client.target(generateURL("/injection-async")).request().get(Integer.class);
assertEquals((Integer) 42, data);
Assertions.assertEquals((Integer) 42, data);
}
}
@@ -1,14 +1,11 @@
package org.jboss.resteasy.rxjava2;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.reactivex.Single;

Expand All @@ -20,27 +17,27 @@ public void testFromCompletionStage() {
final CompletableFuture<Integer> cs = new CompletableFuture<>();
cs.complete(1);
final Single<?> single = provider.fromCompletionStage(cs);
assertEquals(1, single.blockingGet());
Assertions.assertEquals(1, single.blockingGet());
}

@Test
public void testFromCompletionStageNotDeferred() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final Single<?> single = provider.fromCompletionStage(someAsyncMethod(latch));

assertTrue(latch.await(1, TimeUnit.SECONDS));
assertEquals("Hello!", single.blockingGet());
assertEquals(0, latch.getCount());
Assertions.assertTrue(latch.await(1, TimeUnit.SECONDS));
Assertions.assertEquals("Hello!", single.blockingGet());
Assertions.assertEquals(0, latch.getCount());
}

@Test
public void testFromCompletionStageDeferred() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final Single<?> single = provider.fromCompletionStage(() -> someAsyncMethod(latch));

assertFalse(latch.await(1, TimeUnit.SECONDS));
assertEquals("Hello!", single.blockingGet());
assertEquals(0, latch.getCount());
Assertions.assertFalse(latch.await(1, TimeUnit.SECONDS));
Assertions.assertEquals("Hello!", single.blockingGet());
Assertions.assertEquals(0, latch.getCount());
}

private CompletableFuture<String> someAsyncMethod(final CountDownLatch latch) {
Expand All @@ -51,6 +48,6 @@ private CompletableFuture<String> someAsyncMethod(final CountDownLatch latch) {
@Test
public void testToCompletionStageCase() throws Exception {
final Object actual = provider.toCompletionStage(Single.just(1)).toCompletableFuture().get();
assertEquals(1, actual);
Assertions.assertEquals(1, actual);
}
}
Expand Up @@ -7,8 +7,8 @@

import org.jboss.logging.Logger;
import org.jboss.resteasy.rxjava2.i18n.Messages;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
*
Expand All @@ -33,7 +33,7 @@ public void testLocale() throws Exception {
return;
}

Assert.assertEquals(getExpected(BASE + "00", "expectedClientInvocationBuilder", "abc"),
Assertions.assertEquals(getExpected(BASE + "00", "expectedClientInvocationBuilder", "abc"),
Messages.MESSAGES.expectedClientInvocationBuilder("abc"));
}

Expand Down
Expand Up @@ -5,8 +5,8 @@
import java.util.Properties;

import org.jboss.logging.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

/**
*
Expand All @@ -19,12 +19,12 @@ public abstract class TestMessagesParent {
protected static Locale savedLocale;
protected Properties properties = new Properties();

@BeforeClass
@BeforeAll
public static void beforeClass() {
savedLocale = Locale.getDefault();
}

@AfterClass
@AfterAll
public static void afterClass() {
Locale.setDefault(savedLocale);
LOG.info("Reset default locale to: " + savedLocale);
Expand Down

0 comments on commit b376d62

Please sign in to comment.