Skip to content

Update all incubator projects to JUnit 5 #52

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 8 commits 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
9 changes: 7 additions & 2 deletions scijava/scijava-discovery-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@
</dependency>
<!-- 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-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,17 @@

import java.util.List;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.scijava.Context;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.scijava.discovery.Discoverer;
import org.scijava.plugin.PluginService;

public class PluginDiscovererTest {

private static Context ctx;
private static PluginService plugins;

@BeforeClass
public static void setUp() {
ctx = new Context(PluginService.class);
plugins = ctx.getService(PluginService.class);
}

@AfterClass
public static void tearDown() throws Exception {
ctx.close();
plugins = null;
}

@Test
public void testPluginDiscovery() {
Discoverer d = new PluginBasedDiscoverer();
List<TestPlugin> discoveries = d.discover(TestPlugin.class);
Assert.assertTrue(discoveries.stream().anyMatch(o -> o.getClass() == TestPluginImpl.class));
Assertions.assertTrue(discoveries.stream().anyMatch(o -> o.getClass() == TestPluginImpl.class));
}

}
9 changes: 7 additions & 2 deletions scijava/scijava-discovery-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,13 @@
</dependency>
<!-- 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-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.ServiceLoader;
import java.util.stream.Collectors;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.scijava.discovery.Discoverer;
import org.scijava.ops.spi.Op;
import org.scijava.ops.spi.OpCollection;
Expand All @@ -25,8 +25,8 @@ private static <T> void assertDiscoveryRequirements(Discoverer d, Class<T> disco
List<Class<T>> implementingClasses = d.discover(discovery).stream().map(o -> (Class<T>) o.getClass()).collect(
Collectors.toList());
for(Class<? extends T> cls : impls)
Assert.assertTrue(implementingClasses.contains(cls));
Assertions.assertTrue(implementingClasses.contains(cls));

Assert.assertEquals(impls.length, implementingClasses.size());
Assertions.assertEquals(impls.length, implementingClasses.size());
}
}
9 changes: 7 additions & 2 deletions scijava/scijava-discovery-therapi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@
</dependency>
<!-- 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-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@

package org.scijava.discovery.therapi;

import org.junit.jupiter.api.Test;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class TagOptionsTest {

private List<TaggedElement> getTaggedDiscoveries(
String tagType)
{
private List<TaggedElement> getTaggedDiscoveries(String tagType) {
return new TaggedElementDiscoverer(tagType).discover(TaggedElement.class);
}

@Test
public void optionsTest() {
List<TaggedElement> elements = getTaggedDiscoveries(
"optionsTest");
List<TaggedElement> elements = getTaggedDiscoveries("optionsTest");
TaggedElement annotatedElement = elements.get(0);
Assert.assertEquals("e", annotatedElement.option("singleKey"));
Assert.assertEquals("[e1, e2]", annotatedElement.option("listKey"));
assertEquals("e", annotatedElement.option("singleKey"));
assertEquals("[e1, e2]", annotatedElement.option("listKey"));
}

@Test
public void optionsPerLineTest() {
List<TaggedElement> elements = getTaggedDiscoveries(
"optionsPerLineTest");
List<TaggedElement> elements = getTaggedDiscoveries("optionsPerLineTest");
TaggedElement annotatedElement = elements.get(0);
Assert.assertEquals("e", annotatedElement.option("singleKey"));
Assert.assertEquals("[e1, e2]", annotatedElement.option("listKey"));
assertEquals("e", annotatedElement.option("singleKey"));
assertEquals("[e1, e2]", annotatedElement.option("listKey"));
}

/**
Expand All @@ -38,90 +36,90 @@ public void optionsPerLineTest() {
*/
@Test
public void forgottenCommaTest() {
List<TaggedElement> elements = getTaggedDiscoveries(
"forgottenComma");
List<TaggedElement> elements = getTaggedDiscoveries("forgottenComma");
TaggedElement annotatedElement = elements.get(0);
Assert.assertThrows(IllegalArgumentException.class, //
() -> annotatedElement.option("singleKey"));
assertThrows(IllegalArgumentException.class, //
() -> annotatedElement.option("singleKey"));
}

/**
* Tests ability to parse options without quotes.
*/
@Test
public void forgottenQuoteTest() {
List<TaggedElement> elements = getTaggedDiscoveries(
"forgottenQuote");
List<TaggedElement> elements = getTaggedDiscoveries("forgottenQuote");
TaggedElement annotatedElement = elements.get(0);
Assert.assertEquals("e", annotatedElement.option("singleKey"));
assertEquals("e", annotatedElement.option("singleKey"));
}

/**
* Tests duplicate definition behaviors. When a tag tries to define a tag
* twice, we expect that the second definition overwrites the first.
* Tests duplicate definition behaviors. When a tag tries to define a tag twice,
* we expect that the second definition overwrites the first.
*/
@Test
public void duplicateOptionTest() {
List<TaggedElement> elements = getTaggedDiscoveries(
"duplicateOption");
List<TaggedElement> elements = getTaggedDiscoveries("duplicateOption");
TaggedElement annotatedElement = elements.get(0);
Assert.assertEquals("[e1, e2]", annotatedElement.option("singleKey"));
assertEquals("[e1, e2]", annotatedElement.option("singleKey"));
}

/**
* Tests behavior for options not present on a tagged element.
*/
@Test
public void absentOptionTest() {
List<TaggedElement> elements = getTaggedDiscoveries(
"absentOption");
List<TaggedElement> elements = getTaggedDiscoveries("absentOption");
TaggedElement annotatedElement = elements.get(0);
Assert.assertEquals("", annotatedElement.option("singleKey"));
assertEquals("", annotatedElement.option("singleKey"));
}

/**
* @implNote optionsTest singleKey='e', listKey={'e1', 'e2'}
*/
@SuppressWarnings("unused")
public void foo() {}
public void foo() {
}

/**
* @implNote optionsPerLineTest
* singleKey='e',
* listKey={'e1', 'e2'}
* @implNote optionsPerLineTest singleKey='e', listKey={'e1', 'e2'}
*/
@SuppressWarnings("unused")
public void boo() {}
public void boo() {
}

/**
* A tagged element whose tag doesn't have a comma between options
*
* @implNote forgottenComma singleKey='e' listKey={'e1', 'e2'}
*/
@SuppressWarnings("unused")
public void too() {}
public void too() {
}

/**
* A tagged element whose tag doesn't have a quotes surrounding the value
*
* @implNote forgottenQuote singleKey=e, listKey={'e1', 'e2'}
*/
@SuppressWarnings("unused")
public void moo() {}
public void moo() {
}

/**
* A tagged element whose tag tries to define a key twice
*
* @implNote duplicateOption singleKey='e', singleKey={'e1', 'e2'}
*/
@SuppressWarnings("unused")
public void coo() {}
public void coo() {
}

/**
* A tagged element who has no options
*
* @implNote absentOption
*/
@SuppressWarnings("unused")
public void woo() {}
public void woo() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,32 @@
import java.util.List;
import java.util.function.Function;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.scijava.discovery.Discoverer;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class TherapiDiscovererTest {

private Discoverer discoverer()
{
private Discoverer discoverer() {
return new TaggedElementDiscoverer("test");
}

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

@Test
public void discoverField() throws SecurityException {
List<TaggedElement> elements = discoverer().discover(TaggedElement.class);
Assert.assertTrue(elements.stream().anyMatch(d -> {
assertTrue(elements.stream().anyMatch(d -> {
try {
AnnotatedElement actual = d.discovery();
AnnotatedElement expected = this.getClass().getDeclaredField("fieldTest");
return expected.equals(actual);
}
catch (NoSuchFieldException ex) {
} catch (NoSuchFieldException ex) {
return false;
}
}));
Expand All @@ -39,13 +38,12 @@ public void discoverField() throws SecurityException {
@Test
public void discoverMethod() throws SecurityException {
List<TaggedElement> elements = discoverer().discover(TaggedElement.class);
Assert.assertTrue(elements.stream().anyMatch(d -> {
assertTrue(elements.stream().anyMatch(d -> {
try {
AnnotatedElement actual = d.discovery();
AnnotatedElement expected = this.getClass().getDeclaredMethod("methodTest");
return expected.equals(actual);
}
catch (NoSuchMethodException ex) {
} catch (NoSuchMethodException ex) {
return false;
}
}));
Expand All @@ -55,13 +53,13 @@ public void discoverMethod() throws SecurityException {
* @implNote test
*/
public void methodTest() {

}

/**
* @implNote test
*/
public final Function<Integer, Integer> fieldTest = (in) -> in+ 1;
public final Function<Integer, Integer> fieldTest = (in) -> in + 1;
}

/**
Expand All @@ -70,5 +68,5 @@ public void methodTest() {
*
*/
class ClassTest {

}
9 changes: 7 additions & 2 deletions scijava/scijava-log2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@
<dependencies>
<!-- 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-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

package org.scijava.log2;

import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Tests {@link CallingClassUtils}.
Expand Down
Loading