Skip to content

Convert SciJava Types Tests to JUnit 5 #50

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

Merged
merged 1 commit into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions scijava/scijava-types/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@

<!-- Test scope dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@

package org.scijava.types;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -42,6 +39,7 @@
import java.util.ServiceLoader;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.scijava.discovery.Discoverer;
Expand Down Expand Up @@ -77,22 +75,22 @@ public void tearDown() {
@Test
public void testClass() {
final Type stringType = types.reify("Hello");
assertEquals(String.class, stringType);
Assertions.assertEquals(String.class, stringType);
}

/** Tests type extraction for {@code null} objects. */
@Test
public void testNull() {
final Type nullType = types.reify(null);
assertTrue(Any.class.isInstance(nullType));
Assertions.assertTrue(Any.class.isInstance(nullType));
}

/** Tests type extraction for {@link Nil} objects. */
@Test
public void testNil() {
final Nil<List<Float>> nilFloatList = new Nil<List<Float>>() {};
final Type nilFloatListType = types.reify(nilFloatList);
assertEquals(nilFloatList.getType(), nilFloatListType);
Assertions.assertEquals(nilFloatList.getType(), nilFloatListType);
}

/** Tests type extraction for {@link GenericTyped} objects. */
Expand All @@ -105,7 +103,7 @@ public Type getType() {
return Number.class;
}
};
assertEquals(Number.class, types.reify(numberThing));
Assertions.assertEquals(Number.class, types.reify(numberThing));
}

/** Tests type extraction for {@link Iterable} objects. */
Expand All @@ -114,7 +112,7 @@ public void testIterable() {
final List<String> stringList = //
new ArrayList<>(Collections.singletonList("Hi"));
final Type stringListType = types.reify(stringList);
assertEquals(new Nil<ArrayList<String>>() {}.getType(), stringListType);
Assertions.assertEquals(new Nil<ArrayList<String>>() {}.getType(), stringListType);
}

/** Tests type extraction for {@link Map} objects. */
Expand All @@ -123,7 +121,7 @@ public void testMap() {
final Map<String, Integer> mapSI = //
new HashMap<>(Collections.singletonMap("Curtis", 37));
final Type mapSIType = types.reify(mapSI);
assertEquals(new Nil<HashMap<String, Integer>>() {}.getType(), mapSIType);
Assertions.assertEquals(new Nil<HashMap<String, Integer>>() {}.getType(), mapSIType);
}

/** Tests nested type extraction of a complex object. */
Expand All @@ -144,7 +142,7 @@ public void testNested() {
testScores.add(highlights);

final Type testScoresType = types.reify(testScores);
assertEquals(new Nil<ArrayList<HashMap<String, ArrayList<Integer>>>>() {}
Assertions.assertEquals(new Nil<ArrayList<HashMap<String, ArrayList<Integer>>>>() {}
.getType(), testScoresType);
}

Expand All @@ -158,12 +156,12 @@ public void testRecursiveTyping() {
blueBag.add(new BlueThing());

final Type blueBagType = types.reify(blueBag);
assertEquals(new Nil<Bag<BlueThing>>() {}.getType(), blueBagType);
Assertions.assertEquals(new Nil<Bag<BlueThing>>() {}.getType(), blueBagType);

final Bag<RedThing> redBag = new Bag<>();
redBag.add(new RedThing());

final Type redBagType = types.reify(redBag);
assertEquals(new Nil<Bag<RedThing>>() {}.getType(), redBagType);
Assertions.assertEquals(new Nil<Bag<RedThing>>() {}.getType(), redBagType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@

package org.scijava.types;

import static org.junit.Assert.assertTrue;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Observer;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.scijava.Context;
Expand Down Expand Up @@ -91,27 +90,27 @@ public void testConvert() {
// support generic types. Right now, CastingConverter steals this.
// assertConvert(nil, new Nil<Nil<Map<?, ?>>>() {}.getType());
final Converter<?, ?> converter = convert.getHandler(nil, Observer.class);
assertTrue(converter instanceof NilConverter);
Assertions.assertTrue(converter instanceof NilConverter);
// TODO: Enable after Nil proxying is improved to support non-interfaces.
// assertTrue(converter.convert(nil, String.class) instanceof String);
assertTrue(converter.convert(nil, List.class) instanceof List);
assertTrue(converter.convert(nil, new Nil<Map<?, ?>>() {}.getType()) instanceof Map);
// Assertions.assertTrue(converter.convert(nil, String.class) instanceof String);
Assertions.assertTrue(converter.convert(nil, List.class) instanceof List);
Assertions.assertTrue(converter.convert(nil, new Nil<Map<?, ?>>() {}.getType()) instanceof Map);
// TODO: Enable after ConvertService is rewritten to fully
// support generic types. Right now, CastingConverter steals this.
// assertTrue(converter.convert(nil, new Nil<Nil<Map<?, ?>>>() {}.getType()) instanceof Nil);
// Assertions.assertTrue(converter.convert(nil, new Nil<Nil<Map<?, ?>>>() {}.getType()) instanceof Nil);
}

private void assertCanConvert(final Nil<?> nil, final Type destType) {
final Converter<?, ?> converter = convert.getHandler(nil, destType);
assertTrue(converter instanceof NilConverter);
assertTrue(converter.canConvert(nil, destType));
Assertions.assertTrue(converter instanceof NilConverter);
Assertions.assertTrue(converter.canConvert(nil, destType));
}

private void assertConvert(final Nil<?> nil, final Type destType) {
final Converter<?, ?> converter = convert.getHandler(nil, destType);
assertTrue(converter instanceof NilConverter);
Assertions.assertTrue(converter instanceof NilConverter);
final Object o = converter.convert(nil, destType);
assertTrue(Types.raw(destType).isAssignableFrom(o.getClass()));
Assertions.assertTrue(Types.raw(destType).isAssignableFrom(o.getClass()));
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

package org.scijava.types.inference;

import static org.junit.Assert.assertEquals;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
Expand All @@ -13,7 +11,8 @@
import java.util.Map;
import java.util.function.Function;

import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.scijava.types.Any;
import org.scijava.types.Nil;

Expand Down Expand Up @@ -50,7 +49,7 @@ public <T, U extends Comparable<Double>> void testInferFromTypeVar()
TypeVariable<?> typeVarT = (TypeVariable<?>) t;
expected.put(typeVarT, new TypeMapping(typeVarT, Double.class, false));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -74,7 +73,7 @@ public <T extends Number> void testInferFromWildcardExtendingClass()
expected.put(typeVarT, new WildcardTypeMapping(typeVarT, mappedWildcard,
true));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -95,7 +94,7 @@ public <T extends Number> void testInferFromWildcardExtendingClass()
TypeVariable<?> typeVarT = (TypeVariable<?>) t;
expected.put(typeVarT, new TypeMapping(typeVarT, Double.class, false));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -114,7 +113,7 @@ public <T extends Number> void testInferFromWildcardExtendingClass()
Map<TypeVariable<?>, TypeMapping> expected = new HashMap<>();
expected.put(typeVarT, new TypeMapping(typeVarT, Double.class, true));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -133,7 +132,7 @@ public <T extends Number> void testInferFromWildcardExtendingClass()
Map<TypeVariable<?>, TypeMapping> expected = new HashMap<>();
expected.put(typeVarT, new TypeMapping(typeVarT, Double.class, true));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -151,7 +150,7 @@ public <O extends Number> void testInferOToAny()
Map<TypeVariable<?>, TypeMapping> expected = new HashMap<>();
expected.put(typeVarO, new TypeMapping(typeVarO, new Any(), true));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -169,7 +168,7 @@ public <O extends Number> void testInferOToAnyWithClass()
Map<TypeVariable<?>, TypeMapping> expected = new HashMap<>();
expected.put(typeVarO, new TypeMapping(typeVarO, new Any(), true));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -187,7 +186,7 @@ public <O extends Number> void testInferOToAnyWithInterface()
Map<TypeVariable<?>, TypeMapping> expected = new HashMap<>();
expected.put(typeVarO, new TypeMapping(typeVarO, new Any(), true));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -205,7 +204,7 @@ public <O extends Number> void testInferOToAnyWithRawType()
Map<TypeVariable<?>, TypeMapping> expected = new HashMap<>();
expected.put(typeVarO, new TypeMapping(typeVarO, new Any(), true));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -221,7 +220,7 @@ public <O extends RecursiveThing<O>> void testInferRecursiveTypeVar() {
Map<TypeVariable<?>, TypeMapping> expected = new HashMap<>();
expected.put(typeVarO, new TypeMapping(typeVarO, FooThing.class, false));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -240,7 +239,7 @@ public <T extends Number> void testInferSuperWildcard()
TypeVariable<?> typeVarT = (TypeVariable<?>) new Nil<T>() {}.getType();
expected.put(typeVarT, new TypeMapping(typeVarT, Number.class, true));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -260,7 +259,7 @@ public <T extends Number> void testInferSuperWildcard()
TypeVariable<?> typeVarO = (TypeVariable<?>) new Nil<O>() {}.getType();
expected.put(typeVarO, new TypeMapping(typeVarO, Double.class, true));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -282,7 +281,7 @@ public <T extends Number> void testInferTypeVarInconsistentMapping()
Map<TypeVariable<?>, TypeMapping> expected = new HashMap<>();
expected.put(typeVarT, new TypeMapping(typeVarT, Number.class, true));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -305,7 +304,7 @@ public <T extends Number> void testInferWildcardAndClass()
TypeVariable<?> typeVarT = (TypeVariable<?>) t.getType();
expected.put(typeVarT, new TypeMapping(typeVarT, Number.class, true));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);
}

@Test
Expand All @@ -332,7 +331,7 @@ public <I, O> void testSupertypeTypeInference()
.getActualTypeArguments()[0];
expected.put(typeVarO, new TypeMapping(typeVarO, Double.class, false));

assertEquals(typeAssigns, expected);
Assertions.assertEquals(typeAssigns, expected);
}

@Test
Expand All @@ -354,7 +353,7 @@ public <T> void testWildcardTypeInference() throws TypeInferenceException {
TypeVariable<?> typeVar = (TypeVariable<?>) t;
expected.put(typeVar, new TypeMapping(typeVar, Number.class, true));

assertEquals(expected, typeAssigns);
Assertions.assertEquals(expected, typeAssigns);

final Type[] types2 = { t, t };
final Type listWildcardNumber = new Nil<List<? extends Number>>() {}
Expand All @@ -377,7 +376,7 @@ public <T> void testWildcardTypeInference() throws TypeInferenceException {
TypeVariable<?> typeVar2 = (TypeVariable<?>) t;
expected2.put(typeVar2, new TypeMapping(typeVar, Number.class, true));

assertEquals(expected2, typeAssigns2);
Assertions.assertEquals(expected2, typeAssigns2);
}

}