Skip to content

Commit 12476ba

Browse files
Treiblesschorlectrueden
authored andcommitted
Add tests to validate recent fixes
These tests cover commits: - "Use the bound of the TypeVariable as search class" - "Get correct type arguments if src is not parameterized itself"
1 parent 0324520 commit 12476ba

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

src/test/java/org/scijava/ops/util/TypesTest.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
import java.util.List;
6464
import java.util.Map;
6565
import java.util.Set;
66+
import java.util.function.Consumer;
67+
import java.util.function.Function;
6668
import java.util.jar.JarOutputStream;
6769
import java.util.zip.ZipEntry;
6870

@@ -828,6 +830,68 @@ public <T> void testSatisfiesMatchingT() {
828830
assertNotEquals(Types.satisfies(argsMiss, params), -1);
829831

830832
}
833+
834+
/**
835+
* Tests {@link Types#satisfies(Type[], Type[])} when the given type is indirectly parameterized by
836+
* implementing an parameterized interface.
837+
*/
838+
@Test
839+
public <I1, I2> void testSatisfiesIndirectTypeVariables() {
840+
841+
class NestedThingImplOK1 implements NestedThing<Double, Double> {
842+
@Override
843+
public Double apply(Double t) {
844+
// NB: No implementation needed.
845+
return null;
846+
}
847+
}
848+
849+
final Type[] param = new Type[]{new Nil<Function<I1, I2>>() {}.getType()};
850+
Type[] argOK = new Type[]{NestedThingImplOK1.class};
851+
assertEquals(-1, Types.satisfies(argOK, param));
852+
}
853+
854+
/**
855+
* Tests {@link Types#satisfies(Type[], Type[])} when unbounded type variables are expected
856+
* but the given ones are nested and bounded.
857+
*/
858+
@Test
859+
public <I1, I2> void testSatisfiesUnboundedTypeVariables() {
860+
861+
class NestedThingImplOK1 implements Function<Iterable<Double>, Consumer<Double>> {
862+
@Override
863+
public Consumer<Double> apply(Iterable<Double> t) {
864+
// NB: No implementation needed.
865+
return null;
866+
}
867+
}
868+
869+
class NestedThingImplOK2 implements Function<Iterable<Double>, Consumer<Integer>> {
870+
@Override
871+
public Consumer<Integer> apply(Iterable<Double> t) {
872+
// NB: No implementation needed.
873+
return null;
874+
}
875+
}
876+
877+
class NestedThingImplOK3 implements Function<Double, Consumer<Integer>> {
878+
@Override
879+
public Consumer<Integer> apply(Double t) {
880+
// NB: No implementation needed.
881+
return null;
882+
}
883+
}
884+
885+
final Type[] param = new Type[]{new Nil<Function<I1, I2>>() {}.getType()};
886+
Type[] argOK = new Type[]{NestedThingImplOK1.class};
887+
assertEquals(-1, Types.satisfies(argOK, param));
888+
889+
argOK = new Type[]{NestedThingImplOK2.class};
890+
assertEquals(-1, Types.satisfies(argOK, param));
891+
892+
final Type[] argNotOK = new Type[]{NestedThingImplOK3.class};
893+
assertEquals(-1, Types.satisfies(argNotOK, param));
894+
}
831895

832896
/** Tests {@link Types#cast(Object, Class)}. */
833897
@Test
@@ -951,6 +1015,11 @@ private static class LoopingThing extends RecursiveThing<LoopingThing>
9511015
{
9521016
// NB: No implementation needed.
9531017
}
1018+
1019+
interface NestedThing<I1, I2> extends Function<I1, I2>
1020+
{
1021+
// NB: No implementation needed.
1022+
}
9541023

9551024
/** Enumeration for testing conversion to enum types. */
9561025
public static enum Words {

0 commit comments

Comments
 (0)