Skip to content

Commit 4e7ddf3

Browse files
authored
Merge pull request #50 from scijava/scijava/scijava-types/junit-5
Convert SciJava Types Tests to JUnit 5
2 parents acec388 + 902bb70 commit 4e7ddf3

4 files changed

Lines changed: 42 additions & 46 deletions

File tree

scijava/scijava-types/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@
116116

117117
<!-- Test scope dependencies -->
118118
<dependency>
119-
<groupId>junit</groupId>
120-
<artifactId>junit</artifactId>
119+
<groupId>org.junit.jupiter</groupId>
120+
<artifactId>junit-jupiter-api</artifactId>
121121
<scope>test</scope>
122122
</dependency>
123123
<dependency>
124124
<groupId>org.junit.jupiter</groupId>
125-
<artifactId>junit-jupiter-api</artifactId>
125+
<artifactId>junit-jupiter-engine</artifactId>
126126
<scope>test</scope>
127127
</dependency>
128128
</dependencies>

scijava/scijava-types/src/test/java/org/scijava/types/DefaultTypeReifierTest.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929

3030
package org.scijava.types;
3131

32-
import static org.junit.Assert.assertEquals;
33-
import static org.junit.Assert.assertTrue;
34-
3532
import java.lang.reflect.Type;
3633
import java.util.ArrayList;
3734
import java.util.Arrays;
@@ -42,6 +39,7 @@
4239
import java.util.ServiceLoader;
4340

4441
import org.junit.jupiter.api.AfterEach;
42+
import org.junit.jupiter.api.Assertions;
4543
import org.junit.jupiter.api.BeforeEach;
4644
import org.junit.jupiter.api.Test;
4745
import org.scijava.discovery.Discoverer;
@@ -77,22 +75,22 @@ public void tearDown() {
7775
@Test
7876
public void testClass() {
7977
final Type stringType = types.reify("Hello");
80-
assertEquals(String.class, stringType);
78+
Assertions.assertEquals(String.class, stringType);
8179
}
8280

8381
/** Tests type extraction for {@code null} objects. */
8482
@Test
8583
public void testNull() {
8684
final Type nullType = types.reify(null);
87-
assertTrue(Any.class.isInstance(nullType));
85+
Assertions.assertTrue(Any.class.isInstance(nullType));
8886
}
8987

9088
/** Tests type extraction for {@link Nil} objects. */
9189
@Test
9290
public void testNil() {
9391
final Nil<List<Float>> nilFloatList = new Nil<List<Float>>() {};
9492
final Type nilFloatListType = types.reify(nilFloatList);
95-
assertEquals(nilFloatList.getType(), nilFloatListType);
93+
Assertions.assertEquals(nilFloatList.getType(), nilFloatListType);
9694
}
9795

9896
/** Tests type extraction for {@link GenericTyped} objects. */
@@ -105,7 +103,7 @@ public Type getType() {
105103
return Number.class;
106104
}
107105
};
108-
assertEquals(Number.class, types.reify(numberThing));
106+
Assertions.assertEquals(Number.class, types.reify(numberThing));
109107
}
110108

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

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

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

146144
final Type testScoresType = types.reify(testScores);
147-
assertEquals(new Nil<ArrayList<HashMap<String, ArrayList<Integer>>>>() {}
145+
Assertions.assertEquals(new Nil<ArrayList<HashMap<String, ArrayList<Integer>>>>() {}
148146
.getType(), testScoresType);
149147
}
150148

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

160158
final Type blueBagType = types.reify(blueBag);
161-
assertEquals(new Nil<Bag<BlueThing>>() {}.getType(), blueBagType);
159+
Assertions.assertEquals(new Nil<Bag<BlueThing>>() {}.getType(), blueBagType);
162160

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

166164
final Type redBagType = types.reify(redBag);
167-
assertEquals(new Nil<Bag<RedThing>>() {}.getType(), redBagType);
165+
Assertions.assertEquals(new Nil<Bag<RedThing>>() {}.getType(), redBagType);
168166
}
169167
}

scijava/scijava-types/src/test/java/org/scijava/types/NilConverterTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@
2929

3030
package org.scijava.types;
3131

32-
import static org.junit.Assert.assertTrue;
33-
3432
import java.lang.reflect.Type;
3533
import java.util.List;
3634
import java.util.Map;
3735
import java.util.Observer;
3836

3937
import org.junit.jupiter.api.AfterEach;
38+
import org.junit.jupiter.api.Assertions;
4039
import org.junit.jupiter.api.BeforeEach;
4140
import org.junit.jupiter.api.Test;
4241
import org.scijava.Context;
@@ -91,27 +90,27 @@ public void testConvert() {
9190
// support generic types. Right now, CastingConverter steals this.
9291
// assertConvert(nil, new Nil<Nil<Map<?, ?>>>() {}.getType());
9392
final Converter<?, ?> converter = convert.getHandler(nil, Observer.class);
94-
assertTrue(converter instanceof NilConverter);
93+
Assertions.assertTrue(converter instanceof NilConverter);
9594
// TODO: Enable after Nil proxying is improved to support non-interfaces.
96-
// assertTrue(converter.convert(nil, String.class) instanceof String);
97-
assertTrue(converter.convert(nil, List.class) instanceof List);
98-
assertTrue(converter.convert(nil, new Nil<Map<?, ?>>() {}.getType()) instanceof Map);
95+
// Assertions.assertTrue(converter.convert(nil, String.class) instanceof String);
96+
Assertions.assertTrue(converter.convert(nil, List.class) instanceof List);
97+
Assertions.assertTrue(converter.convert(nil, new Nil<Map<?, ?>>() {}.getType()) instanceof Map);
9998
// TODO: Enable after ConvertService is rewritten to fully
10099
// support generic types. Right now, CastingConverter steals this.
101-
// assertTrue(converter.convert(nil, new Nil<Nil<Map<?, ?>>>() {}.getType()) instanceof Nil);
100+
// Assertions.assertTrue(converter.convert(nil, new Nil<Nil<Map<?, ?>>>() {}.getType()) instanceof Nil);
102101
}
103102

104103
private void assertCanConvert(final Nil<?> nil, final Type destType) {
105104
final Converter<?, ?> converter = convert.getHandler(nil, destType);
106-
assertTrue(converter instanceof NilConverter);
107-
assertTrue(converter.canConvert(nil, destType));
105+
Assertions.assertTrue(converter instanceof NilConverter);
106+
Assertions.assertTrue(converter.canConvert(nil, destType));
108107
}
109108

110109
private void assertConvert(final Nil<?> nil, final Type destType) {
111110
final Converter<?, ?> converter = convert.getHandler(nil, destType);
112-
assertTrue(converter instanceof NilConverter);
111+
Assertions.assertTrue(converter instanceof NilConverter);
113112
final Object o = converter.convert(nil, destType);
114-
assertTrue(Types.raw(destType).isAssignableFrom(o.getClass()));
113+
Assertions.assertTrue(Types.raw(destType).isAssignableFrom(o.getClass()));
115114
}
116115

117116
}

scijava/scijava-types/src/test/java/org/scijava/types/inference/InferTypeVariablesTest.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

22
package org.scijava.types.inference;
33

4-
import static org.junit.Assert.assertEquals;
5-
64
import java.lang.reflect.ParameterizedType;
75
import java.lang.reflect.Type;
86
import java.lang.reflect.TypeVariable;
@@ -13,7 +11,8 @@
1311
import java.util.Map;
1412
import java.util.function.Function;
1513

16-
import org.junit.Test;
14+
import org.junit.jupiter.api.Assertions;
15+
import org.junit.jupiter.api.Test;
1716
import org.scijava.types.Any;
1817
import org.scijava.types.Nil;
1918

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

53-
assertEquals(expected, typeAssigns);
52+
Assertions.assertEquals(expected, typeAssigns);
5453
}
5554

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

77-
assertEquals(expected, typeAssigns);
76+
Assertions.assertEquals(expected, typeAssigns);
7877
}
7978

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

98-
assertEquals(expected, typeAssigns);
97+
Assertions.assertEquals(expected, typeAssigns);
9998
}
10099

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

117-
assertEquals(expected, typeAssigns);
116+
Assertions.assertEquals(expected, typeAssigns);
118117
}
119118

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

136-
assertEquals(expected, typeAssigns);
135+
Assertions.assertEquals(expected, typeAssigns);
137136
}
138137

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

154-
assertEquals(expected, typeAssigns);
153+
Assertions.assertEquals(expected, typeAssigns);
155154
}
156155

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

172-
assertEquals(expected, typeAssigns);
171+
Assertions.assertEquals(expected, typeAssigns);
173172
}
174173

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

190-
assertEquals(expected, typeAssigns);
189+
Assertions.assertEquals(expected, typeAssigns);
191190
}
192191

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

208-
assertEquals(expected, typeAssigns);
207+
Assertions.assertEquals(expected, typeAssigns);
209208
}
210209

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

224-
assertEquals(expected, typeAssigns);
223+
Assertions.assertEquals(expected, typeAssigns);
225224
}
226225

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

243-
assertEquals(expected, typeAssigns);
242+
Assertions.assertEquals(expected, typeAssigns);
244243
}
245244

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

263-
assertEquals(expected, typeAssigns);
262+
Assertions.assertEquals(expected, typeAssigns);
264263
}
265264

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

285-
assertEquals(expected, typeAssigns);
284+
Assertions.assertEquals(expected, typeAssigns);
286285
}
287286

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

308-
assertEquals(expected, typeAssigns);
307+
Assertions.assertEquals(expected, typeAssigns);
309308
}
310309

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

335-
assertEquals(typeAssigns, expected);
334+
Assertions.assertEquals(typeAssigns, expected);
336335
}
337336

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

357-
assertEquals(expected, typeAssigns);
356+
Assertions.assertEquals(expected, typeAssigns);
358357

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

380-
assertEquals(expected2, typeAssigns2);
379+
Assertions.assertEquals(expected2, typeAssigns2);
381380
}
382381

383382
}

0 commit comments

Comments
 (0)