Skip to content

Commit

Permalink
[RESTEASY-3450] removed Hamcrest statements. Replaced with junit5 Ass…
Browse files Browse the repository at this point in the history
…ertions
  • Loading branch information
rsearls authored and jamezp committed Mar 20, 2024
1 parent cc0a115 commit 54f0292
Show file tree
Hide file tree
Showing 35 changed files with 317 additions and 376 deletions.
6 changes: 0 additions & 6 deletions resteasy-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<version.com.sun.xml.fastinfoset>2.1.1</version.com.sun.xml.fastinfoset>
<version.commons-io.commons-io>2.11.0</version.commons-io.commons-io>
<version.commons-codec.commons-codec>1.15</version.commons-codec.commons-codec>
<version.hamcrest>1.3</version.hamcrest>
<version.io.netty.netty4>4.1.107.Final</version.io.netty.netty4>
<version.io.vertx>4.4.8</version.io.vertx>
<version.io.undertow>2.3.12.Final</version.io.undertow>
Expand Down Expand Up @@ -884,11 +883,6 @@
<artifactId>jetty-plus</artifactId>
<version>${version.org.eclipse.jetty}</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>${version.hamcrest}</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-api</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions resteasy-reactor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.jboss.resteasy.reactor;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.jboss.resteasy.test.TestPortProvider.generateURL;

import java.time.Duration;
Expand Down Expand Up @@ -165,8 +162,8 @@ public void testSubscriberContext() {
.subscriberContext(Context.of(ctxKey, 24))))
.subscriberContext(ctx -> ctx.put(ctxKey, 42));

assertThat(mono.block(), equalTo("got it-got it-got it"));
assertThat(secrets, equalTo(Arrays.asList(42, 42, 24)));
Assertions.assertEquals(mono.block(), "got it-got it-got it");
Assertions.assertTrue(equalTo(secrets, Arrays.asList(42, 42, 24)));
}

@Test
Expand Down Expand Up @@ -261,7 +258,7 @@ public void close() {
},
t -> {
if (!(t instanceof TimeoutException)) {
assertThat(t.getMessage(), containsString("signal within 500ms")); // crappy assertion:(
Assertions.assertTrue(t.getMessage().contains("signal within 500ms")); // crappy assertion:(
}
latch.countDown();
},
Expand All @@ -286,4 +283,16 @@ public void testInjection() {
Assertions.assertEquals((Integer) 42, data);
}

// the order of the values in the 2 lists must be the same
private boolean equalTo(List<Integer> src, List<Integer> control) {
if (src.size() == control.size()) {
for (int i = 0; i < src.size(); i++) {
if (src.get(i).intValue() != control.get(i).intValue()) {
return false;
}
}
return true;
}
return false;
}
}
4 changes: 0 additions & 4 deletions testsuite/integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,6 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
</dependency>

<dependency>
<groupId>io.reactivex.rxjava2</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.jboss.resteasy.test.core.logging;

import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.core.Is.is;
import static org.jboss.resteasy.test.ContainerConstants.DEFAULT_CONTAINER_QUALIFIER;

import java.util.Map;
Expand All @@ -12,7 +10,6 @@
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.Response;

import org.hamcrest.MatcherAssert;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit5.ArquillianExtension;
Expand Down Expand Up @@ -110,12 +107,14 @@ public void testBuildIn() throws Exception {
Assertions.assertEquals("data", strResponse, "Wrong response");

// assert log messages after request
MatcherAssert.assertThat("Correct body reader was not used/logged", bodyReaderStringLog.count(), greaterThan(0));
MatcherAssert.assertThat("Correct body writer was not used/logged", bodyWriterStringLog.count(), greaterThan(0));
MatcherAssert.assertThat("Correct reader interceptor was not used/logged", readerInterceptorLog.count(),
greaterThan(0));
MatcherAssert.assertThat("Correct writer interceptor was not used/logged", writerInterceptorLog.count(),
greaterThan(0));
Assertions.assertTrue(bodyReaderStringLog.count() > 0,
"Correct body reader was not used/logged");
Assertions.assertTrue(bodyWriterStringLog.count() > 0,
"Correct body writer was not used/logged");
Assertions.assertTrue(readerInterceptorLog.count() > 0,
"Correct reader interceptor was not used/logged");
Assertions.assertTrue(writerInterceptorLog.count() > 0,
"Correct writer interceptor was not used/logged");
}

/**
Expand Down Expand Up @@ -154,14 +153,18 @@ public void testCustom() throws Exception {
Assertions.assertEquals("wi_datadata", strResponse, "Wrong response");

// assert log messages after request
MatcherAssert.assertThat("Incorrect body reader was used/logged", bodyReaderStringLog.count(), is(0));
MatcherAssert.assertThat("Incorrect body writer was used/logged", bodyWriterStringLog.count(), is(0));
MatcherAssert.assertThat("Correct readerInterceptor was not used/logged", readerInterceptorLog.count(),
greaterThan(0));
MatcherAssert.assertThat("Correct writerInterceptor was not used/logged", writerInterceptorLog.count(),
greaterThan(0));
MatcherAssert.assertThat("Correct body reader was not used/logged", bodyReaderCustomLog.count(), greaterThan(0));
MatcherAssert.assertThat("Correct body writer was not used/logged", bodyWriterCustomLog.count(), greaterThan(0));
Assertions.assertEquals(bodyReaderStringLog.count(), 0,
"Incorrect body reader was used/logged");
Assertions.assertEquals(bodyWriterStringLog.count(), 0,
"Incorrect body writer was used/logged");
Assertions.assertTrue(readerInterceptorLog.count() > 0,
"Correct readerInterceptor was not used/logged");
Assertions.assertTrue(writerInterceptorLog.count() > 0,
"Correct writerInterceptor was not used/logged");
Assertions.assertTrue(bodyReaderCustomLog.count() > 0,
"Correct body reader was not used/logged");
Assertions.assertTrue(bodyWriterCustomLog.count() > 0,
"Correct body writer was not used/logged");
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package org.jboss.resteasy.test.core.spi;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;

import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.core.Response;

import org.hamcrest.MatcherAssert;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit5.ArquillianExtension;
Expand Down Expand Up @@ -134,7 +130,7 @@ public void customClassDefaultMethodEjbTest() {
public void customClassDefaultMethodTestHelper(String warName) {
Response response = client.target(PortProviderUtil.generateURL("/patched/pure", warName)).request().get();
Assertions.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
MatcherAssert.assertThat(response.getMediaType().toString(), containsString("text/plain"));
Assertions.assertTrue(response.getMediaType().toString().contains("text/plain"));
}

/**
Expand Down Expand Up @@ -169,7 +165,7 @@ public void customClassCustomMethodEjbTest() {
public void customClassCustomMethodTestHelper(String warName) {
Response response = client.target(PortProviderUtil.generateURL("/patched/custom", warName)).request().get();
Assertions.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
MatcherAssert.assertThat(response.getMediaType().toString(), containsString("application/xml"));
Assertions.assertTrue(response.getMediaType().toString().contains("application/xml"));
}

/**
Expand Down Expand Up @@ -205,7 +201,7 @@ public void defaultClassDefaultMethodEjbTest() {
public void defaultClassDefaultMethodTestHelper(String warName) {
Response response = client.target(PortProviderUtil.generateURL("/pure/pure", warName)).request().get();
Assertions.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
MatcherAssert.assertThat(response.getMediaType().toString(), containsString("text/plain"));
Assertions.assertTrue(response.getMediaType().toString().contains("text/plain"));
}

/**
Expand All @@ -217,7 +213,7 @@ public void defaultClassDefaultMethodTestHelper(String warName) {
public void interfaceTest() {
Response response = client.target(PortProviderUtil.generateURL("/proxy", WAR_NORMAL)).request().get();
Assertions.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
MatcherAssert.assertThat(response.getMediaType().toString(), containsString("application/xml"));
Assertions.assertTrue(response.getMediaType().toString().contains("application/xml"));
}

/**
Expand All @@ -235,7 +231,7 @@ public void proxyTest() {
.proxy(ResourceClassProcessorProxy.class);
String response = proxy.custom();
logger.info(String.format("Proxy response: %s", response));
MatcherAssert.assertThat("Proxy returns wrong response", response, is("<a></a>"));
Assertions.assertEquals(response, "<a></a>", "Proxy returns wrong response");

proxyClient.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.jboss.resteasy.test.core.spi;

import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.jboss.resteasy.test.ContainerConstants.DEFAULT_CONTAINER_QUALIFIER;

import org.hamcrest.MatcherAssert;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
Expand Down Expand Up @@ -62,8 +60,8 @@ public void errorTest() {
deployer.deploy(DEPLOYMENT_NAME);
Assertions.fail("Exception from ResourceClassProcessor was not thrown");
} catch (Exception e) {
MatcherAssert.assertThat("Error message was not printed to server log",
errorLogCounter.count(), greaterThanOrEqualTo(1));
Assertions.assertTrue(errorLogCounter.count() >= 1,
"Error message was not printed to server log");
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.jboss.resteasy.test.crypto;

import static org.hamcrest.CoreMatchers.containsString;

import java.lang.reflect.ReflectPermission;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
Expand All @@ -20,7 +18,6 @@
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.Response;

import org.hamcrest.MatcherAssert;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit5.ArquillianExtension;
Expand Down Expand Up @@ -322,9 +319,10 @@ public void testStaleTimestamp() throws Exception {
Assertions.fail("Validation error excepted.");
} catch (ProcessingException pe) {
UnauthorizedSignatureException e = (UnauthorizedSignatureException) pe.getCause();
MatcherAssert.assertThat("Unexcepted error", e.getMessage(),
containsString("Failed to verify signatures:\r\n"));
MatcherAssert.assertThat("Unexcepted error", e.getMessage(), containsString("Signature is stale"));
Assertions.assertTrue(e.getMessage().contains("Failed to verify signatures:\r\n"),
"Unexcepted error");
Assertions.assertTrue(e.getMessage().contains("Signature is stale"),
"Unexcepted error");
}
response.close();
}
Expand Down Expand Up @@ -445,9 +443,10 @@ public void testExpiresFail() throws Exception {
throw new Exception("Signing error excepted");
} catch (ProcessingException pe) {
UnauthorizedSignatureException e = (UnauthorizedSignatureException) pe.getCause();
MatcherAssert.assertThat("Unexcepted error", e.getMessage(),
containsString("Failed to verify signatures:\r\n"));
MatcherAssert.assertThat("Unexcepted error", e.getMessage(), containsString("Signature expired"));
Assertions.assertTrue(e.getMessage().contains("Failed to verify signatures:\r\n"),
"Unexcepted error");
Assertions.assertTrue(e.getMessage().contains("Signature expired"),
"Unexcepted error");
}
response.close();
}
Expand Down Expand Up @@ -479,9 +478,10 @@ public void testManualFail() throws Exception {
} catch (ProcessingException pe) {
UnauthorizedSignatureException e = (UnauthorizedSignatureException) pe.getCause();
logger.info("UnauthorizedSignatureException message: " + e.getMessage());
MatcherAssert.assertThat("Unexcepted error", e.getMessage(),
containsString("Failed to verify signatures:\r\n"));
MatcherAssert.assertThat("Unexcepted error", e.getMessage(), containsString("Failed to verify signature."));
Assertions.assertTrue(e.getMessage().contains("Failed to verify signatures:\r\n"),
"Unexcepted error");
Assertions.assertTrue(e.getMessage().contains("Failed to verify signature."),
"Unexcepted error");
}
response.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.jboss.resteasy.test.form;

import static org.hamcrest.core.IsNull.notNullValue;

import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Form;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import org.hamcrest.MatcherAssert;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit5.ArquillianExtension;
Expand Down Expand Up @@ -70,7 +67,7 @@ public void testFormParamWithNoQueryParamPut() throws Exception {
Response response = client.target(generateURL("/put/noquery/")).request()
.header("Content-Type", "application/x-www-form-urlencoded")
.put(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
MatcherAssert.assertThat("Wrong response", response, notNullValue());
Assertions.assertTrue(response != null, "Wrong response");

response.bufferEntity();
Assertions.assertEquals("abc xyz", response.readEntity(String.class),
Expand All @@ -90,7 +87,7 @@ public void testFormParamWithNoQueryParamPutEncoded() throws Exception {
.header("Content-Type", "application/x-www-form-urlencoded")
.put(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));

MatcherAssert.assertThat("Wrong response", response, notNullValue());
Assertions.assertTrue(response != null, "Wrong response");
response.bufferEntity();
Assertions.assertEquals("abc+xyz", response.readEntity(String.class),
"Wrong response");
Expand All @@ -109,7 +106,7 @@ public void testFormParamWithNoQueryParamPost() throws Exception {
.header("Content-Type", "application/x-www-form-urlencoded")
.post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));

MatcherAssert.assertThat("Wrong response", response, notNullValue());
Assertions.assertTrue(response != null, "Wrong response");
response.bufferEntity();
Assertions.assertEquals("abc xyz", response.readEntity(String.class),
"Wrong response");
Expand All @@ -128,7 +125,7 @@ public void testFormParamWithNoQueryParamPostEncoded() throws Exception {
.header("Content-Type", "application/x-www-form-urlencoded")
.post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));

MatcherAssert.assertThat("Wrong response", response, notNullValue());
Assertions.assertTrue(response != null, "Wrong response");
response.bufferEntity();
Assertions.assertEquals("abc+xyz", response.readEntity(String.class),
"Wrong response");
Expand All @@ -148,7 +145,7 @@ public void testFormParamWithQueryParamPut() throws Exception {
.header("Content-Type", "application/x-www-form-urlencoded")
.put(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));

MatcherAssert.assertThat("Wrong response", response, notNullValue());
Assertions.assertTrue(response != null, "Wrong response");
response.bufferEntity();
Assertions.assertEquals("abc xyz", response.readEntity(String.class),
"Wrong response");
Expand All @@ -168,7 +165,7 @@ public void testFormParamWithQueryParamPutEncoded() throws Exception {
.header("Content-Type", "application/x-www-form-urlencoded")
.put(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));

MatcherAssert.assertThat("Wrong response", response, notNullValue());
Assertions.assertTrue(response != null, "Wrong response");
response.bufferEntity();
Assertions.assertEquals("abc+xyz", response.readEntity(String.class),
"Wrong response");
Expand All @@ -187,7 +184,7 @@ public void testFormParamWithQueryParamPost() throws Exception {
.header("Content-Type", "application/x-www-form-urlencoded")
.post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));

MatcherAssert.assertThat("Wrong response", response, notNullValue());
Assertions.assertTrue(response != null, "Wrong response");
response.bufferEntity();
Assertions.assertEquals("abc xyz", response.readEntity(String.class),
"Wrong response");
Expand All @@ -206,7 +203,7 @@ public void testFormParamWithQueryParamPostEncoded() throws Exception {
.header("Content-Type", "application/x-www-form-urlencoded")
.post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));

MatcherAssert.assertThat("Wrong response", response, notNullValue());
Assertions.assertTrue(response != null, "Wrong response");
response.bufferEntity();
Assertions.assertEquals("abc+xyz", response.readEntity(String.class),
"Wrong response");
Expand Down

0 comments on commit 54f0292

Please sign in to comment.