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

Fixed flaky tests due to class.getMethods #1525

Merged
merged 3 commits into from
Oct 26, 2021
Merged
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
43 changes: 26 additions & 17 deletions core/src/test/java/feign/TypesResolveReturnTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -39,6 +41,13 @@ interface OverridingConcreteSimple extends Simple {
String get();
}

public Method[] getMethods(Class<?> c) {
Method[] methods = c.getMethods();
Arrays.sort(methods,
Comparator.comparing(o -> (o.getName() + o.getGenericReturnType().getTypeName())));
return methods;
}

@Test
public void simple() {
Method[] methods = Simple.class.getMethods();
Expand Down Expand Up @@ -159,7 +168,7 @@ public void concreteSimpleClassGenericSecondLevel() {

@Test
public void overridingConcreteSimpleClassGenericSecondLevel() {
Method[] methods = OverridingConcreteSimpleClassGenericSecondLevel.class.getMethods();
Method[] methods = getMethods(OverridingConcreteSimpleClassGenericSecondLevel.class);
Assertions.assertThat(methods.length).isEqualTo(2);
Type resolved = Types.resolve(OverridingConcreteSimpleClassGenericSecondLevel.class,
OverridingConcreteSimpleClassGenericSecondLevel.class, methods[0].getGenericReturnType());
Expand Down Expand Up @@ -221,7 +230,7 @@ public void concreteSimpleClassMultipleGenericSecondLevel() {

@Test
public void overridingConcreteSimpleClassMultipleGenericSecondLevel() {
Method[] methods = OverridingConcreteSimpleClassMultipleGenericSecondLevel.class.getMethods();
Method[] methods = getMethods(OverridingConcreteSimpleClassMultipleGenericSecondLevel.class);
Assertions.assertThat(methods.length).isEqualTo(2);
Type resolved =
Types.resolve(OverridingConcreteSimpleClassMultipleGenericSecondLevel.class,
Expand Down Expand Up @@ -255,7 +264,7 @@ public void realizingSimpleClassGenericThirdLevel() {

@Test
public void realizingSimpleClassMultipleGenericThirdLevel() {
Method[] methods = RealizingSimpleClassMultipleGenericThirdLevel.class.getMethods();
Method[] methods = getMethods(RealizingSimpleClassMultipleGenericThirdLevel.class);
Assertions.assertThat(methods.length).isEqualTo(2);
Type resolved = Types.resolve(RealizingSimpleClassMultipleGenericThirdLevel.class,
RealizingSimpleClassMultipleGenericThirdLevel.class, methods[0].getGenericReturnType());
Expand All @@ -269,7 +278,7 @@ public void realizingSimpleClassMultipleGenericThirdLevel() {

@Test
public void realizingOverridingSimpleClassGenericThirdLevel() {
Method[] methods = RealizingOverridingSimpleClassGenericThirdLevel.class.getMethods();
Method[] methods = getMethods(RealizingOverridingSimpleClassGenericThirdLevel.class);
Assertions.assertThat(methods.length).isEqualTo(2);
Type resolved = Types.resolve(RealizingOverridingSimpleClassGenericThirdLevel.class,
RealizingOverridingSimpleClassGenericThirdLevel.class, methods[0].getGenericReturnType());
Expand All @@ -283,7 +292,7 @@ public void realizingOverridingSimpleClassGenericThirdLevel() {

@Test
public void realizingOverridingSimpleClassMultipleGenericThirdLevel() {
Method[] methods = RealizingOverridingSimpleClassMultipleGenericThirdLevel.class.getMethods();
Method[] methods = getMethods(RealizingOverridingSimpleClassMultipleGenericThirdLevel.class);
Assertions.assertThat(methods.length).isEqualTo(2);
Type resolved =
Types.resolve(RealizingOverridingSimpleClassMultipleGenericThirdLevel.class,
Expand Down Expand Up @@ -354,7 +363,7 @@ public void concreteSimpleClassGenericThirdLevel() {

@Test
public void OverridingConcreteSimpleClassGenericThirdLevel() {
Method[] methods = OverridingConcreteSimpleClassGenericThirdLevel.class.getMethods();
Method[] methods = getMethods(OverridingConcreteSimpleClassGenericThirdLevel.class);
Assertions.assertThat(methods.length).isEqualTo(2);
Type resolved = Types.resolve(OverridingConcreteSimpleClassGenericThirdLevel.class,
OverridingConcreteSimpleClassGenericThirdLevel.class, methods[0].getGenericReturnType());
Expand Down Expand Up @@ -452,31 +461,31 @@ public void concreteCollectionGenericFourthLevel() {

@Test
public void overridingConcreteCollectionGenericFourthLevel() {
Method[] methods = OverridingConcreteCollectionGenericFourthLevel.class.getMethods();
Method[] methods = getMethods(OverridingConcreteCollectionGenericFourthLevel.class);
Assertions.assertThat(methods.length).isEqualTo(2);
Type resolved = Types.resolve(OverridingConcreteCollectionGenericFourthLevel.class,
OverridingConcreteCollectionGenericFourthLevel.class, methods[0].getGenericReturnType());
OverridingConcreteCollectionGenericFourthLevel.class, methods[1].getGenericReturnType());
Assertions.assertThat(resolved instanceof ParameterizedType).isTrue();
Type resolved2 = Types.resolve(OverridingConcreteCollectionGenericFourthLevel.class,
OverridingConcreteCollectionGenericFourthLevel.class, methods[1].getGenericReturnType());
OverridingConcreteCollectionGenericFourthLevel.class, methods[0].getGenericReturnType());
Assertions.assertThat(resolved2).isEqualTo(Object.class);
Type resolvedType = Types.resolveReturnType(resolved, resolved2);
Assertions.assertThat(resolvedType).isEqualTo(resolved);
}

@Test
public void overrideOverridingConcreteCollectionGenericFourthLevel() {
Method[] methods = OverrideOverridingConcreteCollectionGenericFourthLevel.class.getMethods();
Method[] methods = getMethods(OverrideOverridingConcreteCollectionGenericFourthLevel.class);
Assertions.assertThat(methods.length).isEqualTo(2);
Type resolved =
Types.resolve(OverrideOverridingConcreteCollectionGenericFourthLevel.class,
OverrideOverridingConcreteCollectionGenericFourthLevel.class,
methods[0].getGenericReturnType());
methods[1].getGenericReturnType());
Assertions.assertThat(resolved instanceof ParameterizedType).isTrue();
Type resolved2 =
Types.resolve(OverrideOverridingConcreteCollectionGenericFourthLevel.class,
OverrideOverridingConcreteCollectionGenericFourthLevel.class,
methods[1].getGenericReturnType());
methods[0].getGenericReturnType());
Assertions.assertThat(resolved2).isEqualTo(Object.class);
Type resolvedType = Types.resolveReturnType(resolved, resolved2);
Assertions.assertThat(resolvedType).isEqualTo(resolved);
Expand Down Expand Up @@ -505,20 +514,20 @@ public void concreteGenericCollectionGenericFifthLevel() {

@Test
public void overridingConcreteGenericCollectionGenericFifthLevel() {
Method[] methods = OverridingConcreteGenericCollectionGenericFifthLevel.class.getMethods();
Method[] methods = getMethods(OverridingConcreteGenericCollectionGenericFifthLevel.class);
Assertions.assertThat(methods.length).isEqualTo(2);
Type resolved =
Types.resolve(OverridingConcreteGenericCollectionGenericFifthLevel.class,
OverridingConcreteGenericCollectionGenericFifthLevel.class,
methods[0].getGenericReturnType());
methods[1].getGenericReturnType());
Assertions.assertThat(resolved instanceof ParameterizedType).isTrue();
Type resolved2 =
Types.resolve(OverridingConcreteGenericCollectionGenericFifthLevel.class,
OverridingConcreteGenericCollectionGenericFifthLevel.class,
methods[1].getGenericReturnType());
methods[0].getGenericReturnType());
Assertions.assertThat(resolved2).isEqualTo(Object.class);
Type resolvedType = Types.resolveReturnType(methods[0].getGenericReturnType(),
methods[1].getGenericReturnType());
Type resolvedType = Types.resolveReturnType(methods[1].getGenericReturnType(),
methods[0].getGenericReturnType());
Assertions.assertThat(resolvedType).isEqualTo(resolved);
}

Expand Down