Skip to content

Commit

Permalink
Migrate all assertions to assertJ (#2261)
Browse files Browse the repository at this point in the history
* Migrate all assertions to assertJ

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run   -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:RELEASE   -Drewrite.activeRecipes=org.openrewrite.java.testing.junit5.AssertToAssertions,org.openrewrite.java.testing.assertj.Assertj

* Remove obsolete testing framework

* Migrate more tests for assertJ and assertThrows

* Remove obsolete testing framework

* Build using junit 5

* Use lambdas on tests

---------

Co-authored-by: Marvin Froeder <[email protected]>
  • Loading branch information
velo and velo authored Dec 12, 2023
1 parent 0668f47 commit 13103e3
Show file tree
Hide file tree
Showing 174 changed files with 5,033 additions and 5,485 deletions.
2 changes: 1 addition & 1 deletion .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom
-XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom
7 changes: 6 additions & 1 deletion annotation-error-decoder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<artifactId>mockwebserver3-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
*/
package feign.error;

import feign.Request;
import feign.Response;
import static feign.Feign.configKey;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import static feign.Feign.configKey;
import feign.Request;
import feign.Response;

public abstract class AbstractAnnotationErrorDecoderTest<T> {

Expand All @@ -36,7 +36,7 @@ Response testResponse(int status) {
}

Response testResponse(int status, String body) {
return testResponse(status, body, new HashMap<String, Collection<String>>());
return testResponse(status, body, new HashMap<>());
}

Response testResponse(int status, String body, Map<String, Collection<String>> headers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,19 @@
package feign.error;

import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

@RunWith(Parameterized.class)
public class AnnotationErrorDecoderAnnotationInheritanceTest extends
AbstractAnnotationErrorDecoderTest<AnnotationErrorDecoderAnnotationInheritanceTest.TestClientInterfaceWithWithMetaAnnotation> {
@Override
public Class<TestClientInterfaceWithWithMetaAnnotation> interfaceAtTest() {
return TestClientInterfaceWithWithMetaAnnotation.class;
}

@Parameters(
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][] {
{"Test Code Specific At Method", 402, "method1Test", MethodLevelDefaultException.class},
Expand All @@ -42,22 +36,23 @@ public static Iterable<Object[]> data() {
{"Test Code Specific At Method", 403, "method2Test", MethodLevelNotFoundException.class},
{"Test Code Specific At Method", 404, "method2Test", ClassLevelNotFoundException.class},
});
}
} // first data value (0) is default

@Parameter // first data value (0) is default
public String testType;

@Parameter(1)
public int errorCode;

@Parameter(2)
public String method;

@Parameter(3)
public Class<? extends Exception> expectedExceptionClass;

@Test
public void test() throws Exception {
@MethodSource("data")
@ParameterizedTest(
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
void test(String testType,
int errorCode,
String method,
Class<? extends Exception> expectedExceptionClass)
throws Exception {
initAnnotationErrorDecoderAnnotationInheritanceTest(testType, errorCode, method,
expectedExceptionClass);
AnnotationErrorDecoder decoder =
AnnotationErrorDecoder.builderFor(TestClientInterfaceWithWithMetaAnnotation.class).build();

Expand All @@ -66,7 +61,7 @@ public void test() throws Exception {
}

@ClassError
interface TestClientInterfaceWithWithMetaAnnotation {
public static interface TestClientInterfaceWithWithMetaAnnotation {
@MethodError
void method1Test();

Expand Down Expand Up @@ -102,4 +97,14 @@ public MethodLevelDefaultException() {}
static class MethodLevelNotFoundException extends Exception {
public MethodLevelNotFoundException() {}
}

public void initAnnotationErrorDecoderAnnotationInheritanceTest(String testType,
int errorCode,
String method,
Class<? extends Exception> expectedExceptionClass) {
this.testType = testType;
this.errorCode = errorCode;
this.method = method;
this.expectedExceptionClass = expectedExceptionClass;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@
package feign.error;

import static org.assertj.core.api.Assertions.assertThat;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method1NotFoundException;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.UnauthenticatedOrUnauthorizedException;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method2NotFoundException;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ServeErrorException;
import java.util.Arrays;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ClassLevelDefaultException;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ClassLevelNotFoundException;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method1DefaultException;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method1NotFoundException;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method2NotFoundException;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method3DefaultException;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ClassLevelDefaultException;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ServeErrorException;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.UnauthenticatedOrUnauthorizedException;

@RunWith(Parameterized.class)
public class AnnotationErrorDecoderClassInheritanceTest extends
AbstractAnnotationErrorDecoderTest<AnnotationErrorDecoderClassInheritanceTest.GrandChild> {

Expand All @@ -38,8 +34,6 @@ public Class<GrandChild> interfaceAtTest() {
return GrandChild.class;
}

@Parameters(
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][] {
{"Test Code Specific At Method", 404, "method1Test", Method1NotFoundException.class},
Expand All @@ -59,22 +53,23 @@ public static Iterable<Object[]> data() {
{"Test Default At Method", 504, "method3Test", Method3DefaultException.class},
{"Test Default At Class", 504, "method2Test", ClassLevelDefaultException.class},
});
}
} // first data value (0) is default

@Parameter // first data value (0) is default
public String testType;

@Parameter(1)
public int errorCode;

@Parameter(2)
public String method;

@Parameter(3)
public Class<? extends Exception> expectedExceptionClass;

@Test
public void test() throws Exception {
@MethodSource("data")
@ParameterizedTest(
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
void test(String testType,
int errorCode,
String method,
Class<? extends Exception> expectedExceptionClass)
throws Exception {
initAnnotationErrorDecoderClassInheritanceTest(testType, errorCode, method,
expectedExceptionClass);
AnnotationErrorDecoder decoder =
AnnotationErrorDecoder.builderFor(GrandChild.class).build();

Expand Down Expand Up @@ -128,4 +123,14 @@ abstract class Child implements ParentInterfaceWithErrorHandling {

abstract class GrandChild extends Child {
}

public void initAnnotationErrorDecoderClassInheritanceTest(String testType,
int errorCode,
String method,
Class<? extends Exception> expectedExceptionClass) {
this.testType = testType;
this.errorCode = errorCode;
this.method = method;
this.expectedExceptionClass = expectedExceptionClass;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,37 @@
*/
package feign.error;

import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import feign.Request;
import feign.codec.Decoder;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DeclaredDefaultConstructorException;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DeclaredDefaultConstructorWithOtherConstructorsException;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefaultConstructorException;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForBody;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForBodyAndHeaders;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForBodyAndHeadersSecondOrder;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForHeaders;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForHeadersButNotForBody;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForNonSupportedBody;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForOptionalBody;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithNoAnnotationForBody;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithRequest;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithRequestAndAnnotationForResponseBody;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithRequestAndResponseBody;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithRequestAndResponseHeadersAndOptionalResponseBody;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithRequestAndResponseHeadersAndResponseBody;
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.ParametersException;
import feign.optionals.OptionalDecoder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.runners.Parameterized.Parameter;
import java.util.*;
import static org.assertj.core.api.Assertions.assertThat;
import static feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors;
import static feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.*;

@RunWith(Parameterized.class)
public class AnnotationErrorDecoderExceptionConstructorsTest extends
AbstractAnnotationErrorDecoderTest<TestClientInterfaceWithDifferentExceptionConstructors> {

Expand All @@ -38,7 +55,7 @@ public class AnnotationErrorDecoderExceptionConstructorsTest extends
"http://test", Collections.emptyMap(), Request.Body.empty(), null);
private static final feign.Request NO_REQUEST = null;
private static final Map<String, Collection<String>> NON_NULL_HEADERS =
new HashMap<String, Collection<String>>();
new HashMap<>();
private static final Map<String, Collection<String>> NO_HEADERS = null;


Expand All @@ -47,8 +64,6 @@ public Class<TestClientInterfaceWithDifferentExceptionConstructors> interfaceAtT
return TestClientInterfaceWithDifferentExceptionConstructors.class;
}

@Parameters(
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][] {
{"Test Default Constructor", 500, DefaultConstructorException.class, NO_REQUEST, NO_BODY,
Expand Down Expand Up @@ -101,28 +116,27 @@ public static Iterable<Object[]> data() {
Optional.of(NON_NULL_BODY),
NON_NULL_HEADERS}
});
}
} // first data value (0) is default

@Parameter // first data value (0) is default
public String testName;

@Parameter(1)
public int errorCode;

@Parameter(2)
public Class<? extends Exception> expectedExceptionClass;

@Parameter(3)
public Object expectedRequest;

@Parameter(4)
public Object expectedBody;

@Parameter(5)
public Map<String, Collection<String>> expectedHeaders;

@Test
public void test() throws Exception {
@MethodSource("data")
@ParameterizedTest(
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
void test(String testName,
int errorCode,
Class<? extends Exception> expectedExceptionClass,
Object expectedRequest,
Object expectedBody,
Map<String, Collection<String>> expectedHeaders)
throws Exception {
initAnnotationErrorDecoderExceptionConstructorsTest(testName, errorCode, expectedExceptionClass,
expectedRequest, expectedBody, expectedHeaders);
AnnotationErrorDecoder decoder = AnnotationErrorDecoder
.builderFor(TestClientInterfaceWithDifferentExceptionConstructors.class)
.withResponseBodyDecoder(new OptionalDecoder(new Decoder.Default()))
Expand All @@ -138,8 +152,18 @@ public void test() throws Exception {
assertThat(exception.headers()).isEqualTo(expectedHeaders);
}

@Test
public void testIfExceptionIsNotInTheList() throws Exception {
@MethodSource("data")
@ParameterizedTest(
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
void ifExceptionIsNotInTheList(String testName,
int errorCode,
Class<? extends Exception> expectedExceptionClass,
Object expectedRequest,
Object expectedBody,
Map<String, Collection<String>> expectedHeaders)
throws Exception {
initAnnotationErrorDecoderExceptionConstructorsTest(testName, errorCode, expectedExceptionClass,
expectedRequest, expectedBody, expectedHeaders);
AnnotationErrorDecoder decoder = AnnotationErrorDecoder
.builderFor(TestClientInterfaceWithDifferentExceptionConstructors.class)
.withResponseBodyDecoder(new OptionalDecoder(new Decoder.Default()))
Expand Down Expand Up @@ -539,4 +563,18 @@ public Map<String, Collection<String>> headers() {
}
}
}

public void initAnnotationErrorDecoderExceptionConstructorsTest(String testName,
int errorCode,
Class<? extends Exception> expectedExceptionClass,
Object expectedRequest,
Object expectedBody,
Map<String, Collection<String>> expectedHeaders) {
this.testName = testName;
this.errorCode = errorCode;
this.expectedExceptionClass = expectedExceptionClass;
this.expectedRequest = expectedRequest;
this.expectedBody = expectedBody;
this.expectedHeaders = expectedHeaders;
}
}
Loading

0 comments on commit 13103e3

Please sign in to comment.