Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate assertions to AssertJ #21

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions dropwizard-jaxws-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<artifactId>dropwizard-jaxws-example</artifactId>
<name>Dropwizard JAX-WS Example Application</name>

<properties>
<h2.version>2.2.224</h2.version>

<maven-shade-plugin.version>3.5.1</maven-shade-plugin.version>
</properties>

<dependencies>

<dependency>
Expand Down Expand Up @@ -59,13 +65,12 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
<version>${h2.version}</version>
</dependency>

<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<version>2.1.2</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -109,7 +114,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<version>${maven-shade-plugin.version}</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
Expand Down
1 change: 0 additions & 1 deletion dropwizard-jaxws/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<version>2.1.2</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

import jakarta.xml.ws.handler.Handler;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

class ClientBuilderTest {
Expand All @@ -32,14 +30,14 @@ void buildClient() {
.cxfOutInterceptors(outInterceptor, outInterceptor)
.cxfOutFaultInterceptors(outFaultInterceptor, outFaultInterceptor);

assertThat(builder.getAddress(), equalTo("address"));
assertThat(builder.getServiceClass(), equalTo(Object.class));
assertThat(builder.getConnectTimeout(), equalTo(1234));
assertThat(builder.getReceiveTimeout(), equalTo(5678));
assertThat(builder.getBindingId(), equalTo("binding id"));
assertThat(builder.getCxfInInterceptors(), contains(new Interceptor<?>[]{ inInterceptor, inInterceptor }));
assertThat(builder.getCxfInFaultInterceptors(), contains(new Interceptor<?>[]{ inFaultInterceptor, inFaultInterceptor }));
assertThat(builder.getCxfOutInterceptors(), contains(new Interceptor<?>[]{ outInterceptor, outInterceptor }));
assertThat(builder.getCxfOutFaultInterceptors(), contains(new Interceptor<?>[]{ outFaultInterceptor, outFaultInterceptor }));
assertThat(builder.getAddress()).isEqualTo("address");
assertThat(builder.getServiceClass()).isEqualTo(Object.class);
assertThat(builder.getConnectTimeout()).isEqualTo(1234);
assertThat(builder.getReceiveTimeout()).isEqualTo(5678);
assertThat(builder.getBindingId()).isEqualTo("binding id");
assertThat(builder.getCxfInInterceptors()).contains(new Interceptor<?>[]{ inInterceptor, inInterceptor });
assertThat(builder.getCxfInFaultInterceptors()).contains(new Interceptor<?>[]{ inFaultInterceptor, inFaultInterceptor });
assertThat(builder.getCxfOutInterceptors()).contains(new Interceptor<?>[]{ outInterceptor, outInterceptor });
assertThat(builder.getCxfOutFaultInterceptors()).contains(new Interceptor<?>[]{ outFaultInterceptor, outFaultInterceptor });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import java.util.Map;

import static org.mockito.Mockito.mock;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
import static org.assertj.core.api.Assertions.assertThat;

class EndpointBuilderTest {

Expand Down Expand Up @@ -38,15 +36,15 @@ void buildEndpoint() {
.cxfOutFaultInterceptors(outFaultInterceptor, outFaultInterceptor)
.properties(props);

assertThat(builder.getPath(), equalTo(path));
assertThat(builder.getService(), equalTo(service));
assertThat(builder.publishedEndpointUrl(), equalTo(publishedUrl));
assertThat(builder.getAuthentication(), equalTo(basicAuth));
assertThat(builder.getSessionFactory(), equalTo(sessionFactory));
assertThat(builder.getCxfInInterceptors(), contains(new Interceptor<?>[]{ inInterceptor, inInterceptor }));
assertThat(builder.getCxfInFaultInterceptors(), contains(new Interceptor<?>[]{ inFaultInterceptor, inFaultInterceptor }));
assertThat(builder.getCxfOutInterceptors(), contains(new Interceptor<?>[]{ outInterceptor, outInterceptor }));
assertThat(builder.getCxfOutFaultInterceptors(), contains(new Interceptor<?>[]{ outFaultInterceptor, outFaultInterceptor }));
assertThat(builder.getProperties().get("key"), equalTo("value"));
assertThat(builder.getPath()).isEqualTo(path);
assertThat(builder.getService()).isEqualTo(service);
assertThat(builder.publishedEndpointUrl()).isEqualTo(publishedUrl);
assertThat(builder.getAuthentication()).isEqualTo(basicAuth);
assertThat(builder.getSessionFactory()).isEqualTo(sessionFactory);
assertThat(builder.getCxfInInterceptors()).contains(new Interceptor<?>[]{ inInterceptor, inInterceptor });
assertThat(builder.getCxfInFaultInterceptors()).contains(new Interceptor<?>[]{ inFaultInterceptor, inFaultInterceptor });
assertThat(builder.getCxfOutInterceptors()).contains(new Interceptor<?>[]{ outInterceptor, outInterceptor });
assertThat(builder.getCxfOutFaultInterceptors()).contains(new Interceptor<?>[]{ outFaultInterceptor, outFaultInterceptor });
assertThat(builder.getProperties().get("key")).isEqualTo("value");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;


class InstrumentedInvokerFactoryTest {

Expand Down Expand Up @@ -103,7 +106,7 @@ private void setTargetMethod(Exchange exchange, String methodName, Class<?>... p
.thenReturn(InstrumentedService.class.getMethod(methodName, parameterTypes));
}
catch (Exception e) {
fail("setTargetMethod failed: " + e.getClass().getName() + ": " + e.getMessage());
fail("setTargetMethod failed", e);
}
}

Expand Down Expand Up @@ -139,10 +142,10 @@ void noAnnotation() {
this.setTargetMethod(exchange, "foo"); // simulate CXF behavior

Object result = invoker.invoke(exchange, null);
assertEquals("fooReturn", result);
assertThat(result).isEqualTo("fooReturn");

assertThat(timer.getCount(), is(oldtimervalue));
assertThat(meter.getCount(), is(oldmetervalue));
assertThat(timer.getCount()).isEqualTo(oldtimervalue);
assertThat(meter.getCount()).isEqualTo(oldmetervalue);
}

@Test
Expand All @@ -160,10 +163,10 @@ void meteredAnnotation() {
this.setTargetMethod(exchange, "metered"); // simulate CXF behavior

Object result = invoker.invoke(exchange, null);
assertEquals("meteredReturn", result);
assertThat(result).isEqualTo("meteredReturn");

assertThat(timer.getCount(), is(oldtimervalue));
assertThat(meter.getCount(), is(1 + oldmetervalue));
assertThat(timer.getCount()).isEqualTo(oldtimervalue);
assertThat(meter.getCount()).isEqualTo(1 + oldmetervalue);
}

@Test
Expand All @@ -181,10 +184,10 @@ void timedAnnotation() {
this.setTargetMethod(exchange, "timed"); // simulate CXF behavior

Object result = invoker.invoke(exchange, null);
assertEquals("timedReturn", result);
assertThat(result).isEqualTo("timedReturn");

assertThat(timer.getCount(), is(1 + oldtimervalue));
assertThat(meter.getCount(), is(oldmetervalue));
assertThat(timer.getCount()).isEqualTo(1 + oldtimervalue);
assertThat(meter.getCount()).isEqualTo(oldmetervalue);
}

@Test
Expand All @@ -207,28 +210,27 @@ void exceptionMeteredAnnotation() {
this.setTargetMethod(exchange, "exceptionMetered", boolean.class); // simulate CXF behavior

Object result = invoker.invoke(exchange, null);
assertEquals("exceptionMeteredReturn", result);
assertThat(result).isEqualTo("exceptionMeteredReturn");

assertThat(timer.getCount(), is(oldtimervalue));
assertThat(meter.getCount(), is(oldmetervalue));
assertThat(exceptionmeter.getCount(), is(oldexceptionmetervalue));
assertThat(timer.getCount()).isEqualTo(oldtimervalue);
assertThat(meter.getCount()).isEqualTo(oldmetervalue);
assertThat(exceptionmeter.getCount()).isEqualTo(oldexceptionmetervalue);

// Invoke InstrumentedResource.exceptionMetered with exception beeing thrown

invoker = invokerBuilder.create(instrumentedService, new ExceptionMeteredInvoker(true));

try {
invoker.invoke(exchange, null);
fail("Exception shall be thrown here");
fail("Exception should be thrown here");
}
catch (Exception e) {
assertThat(e, is(instanceOf(RuntimeException.class)));
assertThat(e).isInstanceOf(RuntimeException.class);
}

assertThat(timer.getCount(), is(oldtimervalue));
assertThat(meter.getCount(), is(oldmetervalue));
assertThat(exceptionmeter.getCount(), is(1 + oldexceptionmetervalue));

assertThat(timer.getCount()).isEqualTo(oldtimervalue);
assertThat(meter.getCount()).isEqualTo(oldmetervalue);
assertThat(exceptionmeter.getCount()).isEqualTo(1 + oldexceptionmetervalue);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
import jakarta.servlet.ServletRegistration;
import jakarta.servlet.http.HttpServlet;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.startsWith;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

class JAXWSBundleTest {

Expand All @@ -42,18 +46,18 @@ void setUp() {
void constructorArgumentChecks() {
try {
new JAXWSBundle<>(null, null);
fail();
fail("expected IllegalArgumentException but no exception thrown");
}
catch (Exception e) {
assertThat(e, is(instanceOf(IllegalArgumentException.class)));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}

try {
new JAXWSBundle<>("soap", null);
fail();
fail("expected IllegalArgumentException but no exception thrown");
}
catch (Exception e) {
assertThat(e, is(instanceOf(IllegalArgumentException.class)));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}
}

Expand All @@ -65,7 +69,7 @@ void initializeAndRun() {
jaxwsBundle.run(null, null);
}
catch (Exception e) {
assertThat(e, is(instanceOf(IllegalArgumentException.class)));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}

jaxwsBundle.initialize(bootstrap);
Expand All @@ -91,7 +95,7 @@ protected String getPublishedEndpointUrlPrefix(Configuration configuration) {
jaxwsBundle.run(null, null);
}
catch (Exception e) {
assertThat(e, is(instanceOf(IllegalArgumentException.class)));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}

jaxwsBundle.initialize(bootstrap);
Expand All @@ -111,26 +115,26 @@ void publishEndpoint() {
Object service = new Object();
try {
jaxwsBundle.publishEndpoint(new EndpointBuilder("foo", null));
fail();
fail("expected IllegalArgumentException but no exception thrown");
}
catch (Exception e) {
assertThat(e, is(instanceOf(IllegalArgumentException.class)));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}

try {
jaxwsBundle.publishEndpoint(new EndpointBuilder(null, service));
fail();
fail("expected IllegalArgumentException but no exception thrown");
}
catch (Exception e) {
assertThat(e, is(instanceOf(IllegalArgumentException.class)));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}

try {
jaxwsBundle.publishEndpoint(new EndpointBuilder(" ", service));
fail();
fail("expected IllegalArgumentException but no exception thrown");
}
catch (Exception e) {
assertThat(e, is(instanceOf(IllegalArgumentException.class)));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}

EndpointBuilder builder = mock(EndpointBuilder.class);
Expand All @@ -148,27 +152,27 @@ void getClient() {

try {
jaxwsBundle.getClient(new ClientBuilder<>(null, null));
fail();
fail("expected IllegalArgumentException but no exception thrown");
}

catch (Exception e) {
assertThat(e, is(instanceOf(IllegalArgumentException.class)));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}

try {
jaxwsBundle.getClient(new ClientBuilder<>(null, url));
fail();
fail("expected IllegalArgumentException but no exception thrown");
}
catch (Exception e) {
assertThat(e, is(instanceOf(IllegalArgumentException.class)));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}

try {
jaxwsBundle.getClient(new ClientBuilder<>(cls, " "));
fail();
fail("expected IllegalArgumentException but no exception thrown");
}
catch (Exception e) {
assertThat(e, is(instanceOf(IllegalArgumentException.class)));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}

ClientBuilder<?> builder = new ClientBuilder<>(cls, url);
Expand Down
Loading
Loading