Skip to content

Commit

Permalink
Migrate from JUnit 4 to 5 (#20)
Browse files Browse the repository at this point in the history
Thanks @openrewrite !

Closes #17
  • Loading branch information
sleberknight authored Nov 6, 2023
1 parent f8bdc6b commit 3befba1
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.transport.Conduit;
import org.apache.cxf.transport.Destination;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

public class BasicAuthenticationInterceptorTest {
class BasicAuthenticationInterceptorTest {

@Mock
private InterceptorChain interceptorChainMock;
Expand All @@ -45,15 +45,15 @@ public class BasicAuthenticationInterceptorTest {
private static final String CORRECT_PASSWORD = "secret";
private static final String USERNAME = "username";

@Before
public void setup() throws IOException {
@BeforeEach
void setup() throws IOException {
MockitoAnnotations.openMocks(this);
when(destinationMock.getBackChannel(any())).thenReturn(conduitMock);
when(outMessageMock.getContent(OutputStream.class)).thenReturn(outputStreamMock);
}

@Test
public void shouldAuthenticateValidUser() {
void shouldAuthenticateValidUser() {
BasicAuthenticationInterceptor target = new BasicAuthenticationInterceptor();
target.setAuthenticator(basicAuthentication);
Message message = createMessageWithUsernameAndPassword(USERNAME, CORRECT_PASSWORD);
Expand All @@ -64,7 +64,7 @@ public void shouldAuthenticateValidUser() {
}

@Test
public void shouldReturnUnathorizedCodeForInvalidCredentials() {
void shouldReturnUnathorizedCodeForInvalidCredentials() {
BasicAuthenticationInterceptor target = new BasicAuthenticationInterceptor();
target.setAuthenticator(basicAuthentication);
Message message = createMessageWithUsernameAndPassword(USERNAME, "foo");
Expand All @@ -75,7 +75,7 @@ public void shouldReturnUnathorizedCodeForInvalidCredentials() {
}

@Test
public void shouldNotCrashOnNullPassword() {
void shouldNotCrashOnNullPassword() {
BasicAuthenticationInterceptor target = new BasicAuthenticationInterceptor();
target.setAuthenticator(basicAuthentication);
Message message = createMessageWithUsernameAndPassword(USERNAME, null);
Expand All @@ -86,7 +86,7 @@ public void shouldNotCrashOnNullPassword() {
}

@Test
public void shouldNotCrashOnNullUser() {
void shouldNotCrashOnNullUser() {
BasicAuthenticationInterceptor target = new BasicAuthenticationInterceptor();
target.setAuthenticator(basicAuthentication);
Message message = createMessageWithUsernameAndPassword(null, CORRECT_PASSWORD);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.roskart.dropwizard.jaxws;

import org.apache.cxf.interceptor.Interceptor;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import jakarta.xml.ws.handler.Handler;

Expand All @@ -10,10 +10,10 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;

public class ClientBuilderTest {
class ClientBuilderTest {

@Test
public void buildClient() {
void buildClient() {

Handler<?> handler = mock(Handler.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

import org.apache.cxf.interceptor.Interceptor;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.mockito.Mockito.*;
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;
public class EndpointBuilderTest {

class EndpointBuilderTest {

@Test
public void buildEndpoint() {
void buildEndpoint() {
Object service = new Object();
String path = "/foo";
String publishedUrl = "http://external/url";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
import org.apache.cxf.service.invoker.Invoker;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.cxf.service.model.OperationInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
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;

public class InstrumentedInvokerFactoryTest {
class InstrumentedInvokerFactoryTest {

// Test service implementation
class InstrumentedService {
Expand Down Expand Up @@ -108,8 +107,8 @@ private void setTargetMethod(Exchange exchange, String methodName, Class<?>... p
}
}

@Before
public void setUp() {
@BeforeEach
void setUp() {
exchange = mock(Exchange.class);

BindingOperationInfo boi = mock(BindingOperationInfo.class);
Expand All @@ -126,7 +125,7 @@ public void setUp() {
}

@Test
public void noAnnotation() {
void noAnnotation() {

Timer timer = testMetricRegistry.timer("timed");
Meter meter = testMetricRegistry.meter("metered");
Expand All @@ -147,7 +146,7 @@ public void noAnnotation() {
}

@Test
public void meteredAnnotation() {
void meteredAnnotation() {

Timer timer = testMetricRegistry.timer("timed");
Meter meter = testMetricRegistry.meter("metered");
Expand All @@ -168,7 +167,7 @@ public void meteredAnnotation() {
}

@Test
public void timedAnnotation() {
void timedAnnotation() {

Timer timer = testMetricRegistry.timer("timed");
Meter meter = testMetricRegistry.meter("metered");
Expand All @@ -189,7 +188,7 @@ public void timedAnnotation() {
}

@Test
public void exceptionMeteredAnnotation() {
void exceptionMeteredAnnotation() {

Timer timer = testMetricRegistry.timer("timed");
Meter meter = testMetricRegistry.meter("metered");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
import io.dropwizard.core.setup.Bootstrap;
import io.dropwizard.core.setup.Environment;
import io.dropwizard.jetty.setup.ServletEnvironment;
import org.junit.Before;
import org.junit.Test;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.servlet.Servlet;
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.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.*;

public class JAXWSBundleTest {
class JAXWSBundleTest {

Environment environment = mock(Environment.class);
Bootstrap<?> bootstrap = mock(Bootstrap.class);
Expand All @@ -29,8 +28,8 @@ public class JAXWSBundleTest {
JAXWSEnvironment jaxwsEnvironment = mock(JAXWSEnvironment.class);
LifecycleEnvironment lifecycleEnvironment = mock(LifecycleEnvironment.class);

@Before
public void setUp() {
@BeforeEach
void setUp() {
when(environment.servlets()).thenReturn(servletEnvironment);
when(environment.lifecycle()).thenReturn(lifecycleEnvironment);
when(bootstrap.getMetricRegistry()).thenReturn(mock(MetricRegistry.class));
Expand All @@ -40,7 +39,7 @@ public void setUp() {
}

@Test
public void constructorArgumentChecks() {
void constructorArgumentChecks() {
try {
new JAXWSBundle<>(null, null);
fail();
Expand All @@ -59,7 +58,7 @@ public void constructorArgumentChecks() {
}

@Test
public void initializeAndRun() {
void initializeAndRun() {
JAXWSBundle<?> jaxwsBundle = new JAXWSBundle<>("/soap", jaxwsEnvironment);

try {
Expand All @@ -80,7 +79,7 @@ public void initializeAndRun() {
}

@Test
public void initializeAndRunWithPublishedEndpointUrlPrefix() {
void initializeAndRunWithPublishedEndpointUrlPrefix() {
JAXWSBundle<?> jaxwsBundle = new JAXWSBundle<Configuration>("/soap", jaxwsEnvironment) {
@Override
protected String getPublishedEndpointUrlPrefix(Configuration configuration) {
Expand All @@ -106,7 +105,7 @@ protected String getPublishedEndpointUrlPrefix(Configuration configuration) {
}

@Test
public void publishEndpoint() {
void publishEndpoint() {

JAXWSBundle<?> jaxwsBundle = new JAXWSBundle<>("/soap", jaxwsEnvironment);
Object service = new Object();
Expand Down Expand Up @@ -140,7 +139,7 @@ public void publishEndpoint() {
}

@Test
public void getClient() {
void getClient() {

JAXWSBundle<?> jaxwsBundle = new JAXWSBundle<>("/soap", jaxwsEnvironment);

Expand Down
Loading

0 comments on commit 3befba1

Please sign in to comment.