forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#34098 from mkouba/synthetic-ip-fixreflookup
ArC: implement equals/hashCode for TypeVariableImpl and WildcardTypeImpl
- Loading branch information
Showing
5 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ent-projects/arc/runtime/src/test/java/io/quarkus/arc/impl/ParameterizedTypeImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.quarkus.arc.impl; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.enterprise.util.TypeLiteral; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class ParameterizedTypeImplTest { | ||
|
||
@SuppressWarnings("serial") | ||
@Test | ||
public void testEqualsAndHashCode() { | ||
// List<?> | ||
ParameterizedTypeImpl parameterizedType1 = new ParameterizedTypeImpl(List.class, WildcardTypeImpl.defaultInstance()); | ||
TypeLiteral<List<?>> literal1 = new TypeLiteral<List<?>>() { | ||
}; | ||
assertEquals(parameterizedType1, literal1.getType()); | ||
assertEquals(parameterizedType1.hashCode(), literal1.hashCode()); | ||
assertEquals(parameterizedType1, | ||
new ParameterizedTypeImpl(List.class, WildcardTypeImpl.defaultInstance())); | ||
|
||
// List<String> | ||
ParameterizedTypeImpl parameterizedType2 = new ParameterizedTypeImpl(List.class, String.class); | ||
TypeLiteral<List<String>> literal2 = new TypeLiteral<List<String>>() { | ||
}; | ||
assertEquals(parameterizedType2, | ||
new ParameterizedTypeImpl(List.class, String.class)); | ||
assertEquals(parameterizedType2, literal2.getType()); | ||
assertEquals(parameterizedType2.hashCode(), literal2.getType().hashCode()); | ||
|
||
// List<? extends Number> | ||
ParameterizedTypeImpl parameterizedType3 = new ParameterizedTypeImpl(List.class, | ||
WildcardTypeImpl.withUpperBound(Number.class)); | ||
TypeLiteral<List<? extends Number>> literal3 = new TypeLiteral<List<? extends Number>>() { | ||
}; | ||
assertEquals(parameterizedType3, literal3.getType()); | ||
assertEquals(parameterizedType3.hashCode(), literal3.getType().hashCode()); | ||
assertEquals(parameterizedType3.hashCode(), new ParameterizedTypeImpl(List.class, | ||
WildcardTypeImpl.withUpperBound(Number.class)).hashCode()); | ||
assertNotEquals(parameterizedType3, parameterizedType1); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
independent-projects/arc/runtime/src/test/java/io/quarkus/arc/impl/TypeVariableImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.quarkus.arc.impl; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class TypeVariableImplTest { | ||
|
||
@Test | ||
public void testEqualsAndHashCode() { | ||
assertEquals(new TypeVariableImpl<>("T"), new TypeVariableImpl<>("T")); | ||
assertNotEquals(new TypeVariableImpl<>("T"), new TypeVariableImpl<>("T", String.class)); | ||
assertEquals(new TypeVariableImpl<>("T").hashCode(), new TypeVariableImpl<>("T").hashCode()); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
independent-projects/arc/runtime/src/test/java/io/quarkus/arc/impl/WildcardTypeImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.quarkus.arc.impl; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class WildcardTypeImplTest { | ||
|
||
@Test | ||
public void testEqualsAndHashCode() { | ||
assertEquals(WildcardTypeImpl.defaultInstance(), WildcardTypeImpl.withUpperBound(Object.class)); | ||
assertEquals(WildcardTypeImpl.withLowerBound(String.class), WildcardTypeImpl.withLowerBound(String.class)); | ||
assertNotEquals(WildcardTypeImpl.withLowerBound(String.class), WildcardTypeImpl.withLowerBound(Integer.class)); | ||
assertEquals(WildcardTypeImpl.defaultInstance().hashCode(), WildcardTypeImpl.withUpperBound(Object.class).hashCode()); | ||
assertEquals(WildcardTypeImpl.withLowerBound(String.class).hashCode(), | ||
WildcardTypeImpl.withLowerBound(String.class).hashCode()); | ||
} | ||
|
||
} |