Skip to content

Commit d8a0097

Browse files
gselzerctrueden
authored andcommitted
Upgrade SciJava Discovery Therapi to JUnit 5
1 parent 9452b7f commit d8a0097

3 files changed

Lines changed: 54 additions & 53 deletions

File tree

scijava/scijava-discovery-therapi/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,13 @@
114114
</dependency>
115115
<!-- Test scope dependencies -->
116116
<dependency>
117-
<groupId>junit</groupId>
118-
<artifactId>junit</artifactId>
117+
<groupId>org.junit.jupiter</groupId>
118+
<artifactId>junit-jupiter-api</artifactId>
119+
<scope>test</scope>
120+
</dependency>
121+
<dependency>
122+
<groupId>org.junit.jupiter</groupId>
123+
<artifactId>junit-jupiter-engine</artifactId>
119124
<scope>test</scope>
120125
</dependency>
121126
</dependencies>
Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11

22
package org.scijava.discovery.therapi;
33

4+
import org.junit.jupiter.api.Test;
5+
46
import java.util.List;
57

6-
import org.junit.Assert;
7-
import org.junit.Test;
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.junit.jupiter.api.Assertions.assertThrows;
810

911
public class TagOptionsTest {
1012

11-
private List<TaggedElement> getTaggedDiscoveries(
12-
String tagType)
13-
{
13+
private List<TaggedElement> getTaggedDiscoveries(String tagType) {
1414
return new TaggedElementDiscoverer(tagType).discover(TaggedElement.class);
1515
}
1616

1717
@Test
1818
public void optionsTest() {
19-
List<TaggedElement> elements = getTaggedDiscoveries(
20-
"optionsTest");
19+
List<TaggedElement> elements = getTaggedDiscoveries("optionsTest");
2120
TaggedElement annotatedElement = elements.get(0);
22-
Assert.assertEquals("e", annotatedElement.option("singleKey"));
23-
Assert.assertEquals("[e1, e2]", annotatedElement.option("listKey"));
21+
assertEquals("e", annotatedElement.option("singleKey"));
22+
assertEquals("[e1, e2]", annotatedElement.option("listKey"));
2423
}
2524

2625
@Test
2726
public void optionsPerLineTest() {
28-
List<TaggedElement> elements = getTaggedDiscoveries(
29-
"optionsPerLineTest");
27+
List<TaggedElement> elements = getTaggedDiscoveries("optionsPerLineTest");
3028
TaggedElement annotatedElement = elements.get(0);
31-
Assert.assertEquals("e", annotatedElement.option("singleKey"));
32-
Assert.assertEquals("[e1, e2]", annotatedElement.option("listKey"));
29+
assertEquals("e", annotatedElement.option("singleKey"));
30+
assertEquals("[e1, e2]", annotatedElement.option("listKey"));
3331
}
3432

3533
/**
@@ -38,90 +36,90 @@ public void optionsPerLineTest() {
3836
*/
3937
@Test
4038
public void forgottenCommaTest() {
41-
List<TaggedElement> elements = getTaggedDiscoveries(
42-
"forgottenComma");
39+
List<TaggedElement> elements = getTaggedDiscoveries("forgottenComma");
4340
TaggedElement annotatedElement = elements.get(0);
44-
Assert.assertThrows(IllegalArgumentException.class, //
45-
() -> annotatedElement.option("singleKey"));
41+
assertThrows(IllegalArgumentException.class, //
42+
() -> annotatedElement.option("singleKey"));
4643
}
4744

4845
/**
4946
* Tests ability to parse options without quotes.
5047
*/
5148
@Test
5249
public void forgottenQuoteTest() {
53-
List<TaggedElement> elements = getTaggedDiscoveries(
54-
"forgottenQuote");
50+
List<TaggedElement> elements = getTaggedDiscoveries("forgottenQuote");
5551
TaggedElement annotatedElement = elements.get(0);
56-
Assert.assertEquals("e", annotatedElement.option("singleKey"));
52+
assertEquals("e", annotatedElement.option("singleKey"));
5753
}
5854

5955
/**
60-
* Tests duplicate definition behaviors. When a tag tries to define a tag
61-
* twice, we expect that the second definition overwrites the first.
56+
* Tests duplicate definition behaviors. When a tag tries to define a tag twice,
57+
* we expect that the second definition overwrites the first.
6258
*/
6359
@Test
6460
public void duplicateOptionTest() {
65-
List<TaggedElement> elements = getTaggedDiscoveries(
66-
"duplicateOption");
61+
List<TaggedElement> elements = getTaggedDiscoveries("duplicateOption");
6762
TaggedElement annotatedElement = elements.get(0);
68-
Assert.assertEquals("[e1, e2]", annotatedElement.option("singleKey"));
63+
assertEquals("[e1, e2]", annotatedElement.option("singleKey"));
6964
}
7065

7166
/**
7267
* Tests behavior for options not present on a tagged element.
7368
*/
7469
@Test
7570
public void absentOptionTest() {
76-
List<TaggedElement> elements = getTaggedDiscoveries(
77-
"absentOption");
71+
List<TaggedElement> elements = getTaggedDiscoveries("absentOption");
7872
TaggedElement annotatedElement = elements.get(0);
79-
Assert.assertEquals("", annotatedElement.option("singleKey"));
73+
assertEquals("", annotatedElement.option("singleKey"));
8074
}
8175

8276
/**
8377
* @implNote optionsTest singleKey='e', listKey={'e1', 'e2'}
8478
*/
8579
@SuppressWarnings("unused")
86-
public void foo() {}
80+
public void foo() {
81+
}
8782

8883
/**
89-
* @implNote optionsPerLineTest
90-
* singleKey='e',
91-
* listKey={'e1', 'e2'}
84+
* @implNote optionsPerLineTest singleKey='e', listKey={'e1', 'e2'}
9285
*/
9386
@SuppressWarnings("unused")
94-
public void boo() {}
87+
public void boo() {
88+
}
9589

9690
/**
9791
* A tagged element whose tag doesn't have a comma between options
9892
*
9993
* @implNote forgottenComma singleKey='e' listKey={'e1', 'e2'}
10094
*/
10195
@SuppressWarnings("unused")
102-
public void too() {}
96+
public void too() {
97+
}
10398

10499
/**
105100
* A tagged element whose tag doesn't have a quotes surrounding the value
106101
*
107102
* @implNote forgottenQuote singleKey=e, listKey={'e1', 'e2'}
108103
*/
109104
@SuppressWarnings("unused")
110-
public void moo() {}
105+
public void moo() {
106+
}
111107

112108
/**
113109
* A tagged element whose tag tries to define a key twice
114110
*
115111
* @implNote duplicateOption singleKey='e', singleKey={'e1', 'e2'}
116112
*/
117113
@SuppressWarnings("unused")
118-
public void coo() {}
114+
public void coo() {
115+
}
119116

120117
/**
121118
* A tagged element who has no options
122119
*
123120
* @implNote absentOption
124121
*/
125122
@SuppressWarnings("unused")
126-
public void woo() {}
123+
public void woo() {
124+
}
127125
}

scijava/scijava-discovery-therapi/src/test/java/org/scijava/discovery/therapi/TherapiDiscovererTest.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,32 @@
44
import java.util.List;
55
import java.util.function.Function;
66

7-
import org.junit.Assert;
8-
import org.junit.Test;
7+
import org.junit.jupiter.api.Test;
98
import org.scijava.discovery.Discoverer;
109

10+
import static org.junit.jupiter.api.Assertions.assertTrue;
11+
1112
public class TherapiDiscovererTest {
1213

13-
private Discoverer discoverer()
14-
{
14+
private Discoverer discoverer() {
1515
return new TaggedElementDiscoverer("test");
1616
}
1717

1818
@Test
1919
public void discoverClass() {
2020
List<TaggedElement> elements = discoverer().discover(TaggedElement.class);
21-
Assert.assertTrue(elements.stream().anyMatch(e -> e.discovery() == ClassTest.class));
21+
assertTrue(elements.stream().anyMatch(e -> e.discovery() == ClassTest.class));
2222
}
2323

2424
@Test
2525
public void discoverField() throws SecurityException {
2626
List<TaggedElement> elements = discoverer().discover(TaggedElement.class);
27-
Assert.assertTrue(elements.stream().anyMatch(d -> {
27+
assertTrue(elements.stream().anyMatch(d -> {
2828
try {
2929
AnnotatedElement actual = d.discovery();
3030
AnnotatedElement expected = this.getClass().getDeclaredField("fieldTest");
3131
return expected.equals(actual);
32-
}
33-
catch (NoSuchFieldException ex) {
32+
} catch (NoSuchFieldException ex) {
3433
return false;
3534
}
3635
}));
@@ -39,13 +38,12 @@ public void discoverField() throws SecurityException {
3938
@Test
4039
public void discoverMethod() throws SecurityException {
4140
List<TaggedElement> elements = discoverer().discover(TaggedElement.class);
42-
Assert.assertTrue(elements.stream().anyMatch(d -> {
41+
assertTrue(elements.stream().anyMatch(d -> {
4342
try {
4443
AnnotatedElement actual = d.discovery();
4544
AnnotatedElement expected = this.getClass().getDeclaredMethod("methodTest");
4645
return expected.equals(actual);
47-
}
48-
catch (NoSuchMethodException ex) {
46+
} catch (NoSuchMethodException ex) {
4947
return false;
5048
}
5149
}));
@@ -55,13 +53,13 @@ public void discoverMethod() throws SecurityException {
5553
* @implNote test
5654
*/
5755
public void methodTest() {
58-
56+
5957
}
6058

6159
/**
6260
* @implNote test
6361
*/
64-
public final Function<Integer, Integer> fieldTest = (in) -> in+ 1;
62+
public final Function<Integer, Integer> fieldTest = (in) -> in + 1;
6563
}
6664

6765
/**
@@ -70,5 +68,5 @@ public void methodTest() {
7068
*
7169
*/
7270
class ClassTest {
73-
71+
7472
}

0 commit comments

Comments
 (0)