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 <velobr@gmail.com>
  • Loading branch information
velo and velo authored Dec 12, 2023
1 parent 2a72821 commit fd360d9
Show file tree
Hide file tree
Showing 147 changed files with 4,165 additions and 3,960 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 @@ -35,7 +35,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 @@ -18,13 +18,9 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
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 org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

@RunWith(Parameterized.class)
public class AnnotationErrorDecoderAnnotationInheritanceTest
extends AbstractAnnotationErrorDecoderTest<
AnnotationErrorDecoderAnnotationInheritanceTest.TestClientInterfaceWithWithMetaAnnotation> {
Expand All @@ -33,8 +29,6 @@ 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[][] {
Expand All @@ -45,22 +39,24 @@ 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 @@ -69,7 +65,7 @@ public void test() throws Exception {
}

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

Expand Down Expand Up @@ -117,4 +113,15 @@ 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 @@ -24,13 +24,9 @@
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ServeErrorException;
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.UnauthenticatedOrUnauthorizedException;
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 org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

@RunWith(Parameterized.class)
public class AnnotationErrorDecoderClassInheritanceTest
extends AbstractAnnotationErrorDecoderTest<
AnnotationErrorDecoderClassInheritanceTest.GrandChild> {
Expand All @@ -40,8 +36,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[][] {
Expand Down Expand Up @@ -78,22 +72,24 @@ 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();

assertThat(decoder.decode(feignConfigKey(method), testResponse(errorCode)).getClass())
Expand Down Expand Up @@ -157,4 +153,15 @@ class ServeErrorException extends Exception {}
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,21 +13,38 @@
*/
package feign.error;

import static feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors;
import static feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.*;
import static org.assertj.core.api.Assertions.assertThat;

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 java.util.*;
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;

@RunWith(Parameterized.class)
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;

public class AnnotationErrorDecoderExceptionConstructorsTest
extends AbstractAnnotationErrorDecoderTest<
TestClientInterfaceWithDifferentExceptionConstructors> {
Expand All @@ -43,17 +60,14 @@ public class AnnotationErrorDecoderExceptionConstructorsTest
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>>();
private static final Map<String, Collection<String>> NON_NULL_HEADERS = new HashMap<>();
private static final Map<String, Collection<String>> NO_HEADERS = null;

@Override
public Class<TestClientInterfaceWithDifferentExceptionConstructors> interfaceAtTest() {
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[][] {
Expand Down Expand Up @@ -186,28 +200,33 @@ public static Iterable<Object[]> data() {
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)
Expand All @@ -226,8 +245,24 @@ 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)
Expand Down Expand Up @@ -649,4 +684,19 @@ 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 fd360d9

Please sign in to comment.