This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new c92fa5ad66 Add JUnit 5 in test dependencies for progressive migration.
Opportunistically upgrade `ArgumentChecks` to JUnit 5, after its change for
testing negative zeros.
c92fa5ad66 is described below
commit c92fa5ad66fdb99b68d68cc3305fb7121b9db55d
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Mon Aug 28 18:13:47 2023 +0200
Add JUnit 5 in test dependencies for progressive migration.
Opportunistically upgrade `ArgumentChecks` to JUnit 5,
after its change for testing negative zeros.
---
endorsed/build.gradle.kts | 3 +-
.../test/module-info.java | 1 +
.../main/org/apache/sis/util/ArgumentChecks.java | 6 ++-
.../org/apache/sis/util/ArgumentChecksTest.java | 49 ++++++++++++++--------
incubator/build.gradle.kts | 3 +-
.../test/module-info.java | 2 +
netbeans-project/ivy.xml | 1 +
netbeans-project/nbproject/project.properties | 35 ++++++++--------
optional/build.gradle.kts | 3 +-
.../test/module-info.java | 2 +
settings.gradle.kts | 1 +
11 files changed, 67 insertions(+), 39 deletions(-)
diff --git a/endorsed/build.gradle.kts b/endorsed/build.gradle.kts
index a1c29e321f..82fe277188 100644
--- a/endorsed/build.gradle.kts
+++ b/endorsed/build.gradle.kts
@@ -67,6 +67,7 @@ dependencies {
// Test dependencies
testImplementation(tests.junit4)
+ testImplementation(tests.junit5)
testImplementation(tests.geoapi)
testImplementation(tests.jama)
testImplementation(tests.geographiclib)
@@ -98,7 +99,7 @@ tasks.compileJava {
}
tasks.compileTestJava {
srcDir.list().forEach {
- addRead(options.compilerArgs, it, "org.apache.sis.test.endorsed,junit")
+ addRead(options.compilerArgs, it,
"org.apache.sis.test.endorsed,org.junit.jupiter.api,junit")
}
addExportForTests(options.compilerArgs)
}
diff --git a/endorsed/src/org.apache.sis.test.endorsed/test/module-info.java
b/endorsed/src/org.apache.sis.test.endorsed/test/module-info.java
index 5530caf16d..56af08af67 100644
--- a/endorsed/src/org.apache.sis.test.endorsed/test/module-info.java
+++ b/endorsed/src/org.apache.sis.test.endorsed/test/module-info.java
@@ -24,6 +24,7 @@
*/
module org.apache.sis.test.endorsed {
requires transitive junit;
+ requires transitive org.junit.jupiter.api;
requires transitive org.opengis.geoapi.conformance;
requires transitive org.apache.derby.tools;
requires transitive org.hsqldb;
diff --git
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/ArgumentChecks.java
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/ArgumentChecks.java
index b075df3d48..ff6ee7cd18 100644
---
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/ArgumentChecks.java
+++
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/ArgumentChecks.java
@@ -465,7 +465,8 @@ public final class ArgumentChecks extends Static {
public static void ensurePositive(final String name, final float value)
throws IllegalArgumentException
{
- if (!(value >= 0)) { //
Use `!` for catching NaN.
+ // Use `!` for catching NaN.
+ if (!(value >= 0) || Float.floatToRawIntBits(value) ==
Integer.MIN_VALUE) {
throw new IllegalArgumentException(Float.isNaN(value) ?
Errors.format(Errors.Keys.NotANumber_1, name) :
Errors.format(Errors.Keys.NegativeArgument_2, name,
value));
@@ -486,7 +487,8 @@ public final class ArgumentChecks extends Static {
public static void ensurePositive(final String name, final double value)
throws IllegalArgumentException
{
- if (!(value >= 0)) { //
Use `!` for catching NaN.
+ // Use `!` for catching NaN.
+ if (!(value >= 0) || Double.doubleToRawLongBits(value) ==
Long.MIN_VALUE) {
throw new IllegalArgumentException(Double.isNaN(value) ?
Errors.format(Errors.Keys.NotANumber_1, name) :
Errors.format(Errors.Keys.NegativeArgument_2, name,
value));
diff --git
a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/ArgumentChecksTest.java
b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/ArgumentChecksTest.java
index 41122b0d0e..29a7c0671e 100644
---
a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/ArgumentChecksTest.java
+++
b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/ArgumentChecksTest.java
@@ -20,14 +20,14 @@ import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Tests the {@link ArgumentChecks} static methods.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.4
* @since 0.4
*/
@DependsOn(org.apache.sis.util.resources.IndexedResourceBundleTest.class)
@@ -43,18 +43,14 @@ public final class ArgumentChecksTest extends TestCase {
*/
@Test
public void testEnsureNonNullElement() {
- try {
+ NullArgumentException e = assertThrows(NullArgumentException.class, ()
-> {
ArgumentChecks.ensureNonNullElement("axes", 2, null);
- fail("Expected a NullArgumentException.");
- } catch (NullArgumentException e) {
- assertTrue(e.getMessage().contains("axes[2]"));
- }
- try {
+ });
+ assertTrue(e.getMessage().contains("axes[2]"));
+ e = assertThrows(NullArgumentException.class, () -> {
ArgumentChecks.ensureNonNullElement("axes[#].unit", 2, null);
- fail("Expected a NullArgumentException.");
- } catch (NullArgumentException e) {
- assertTrue(e.getMessage().contains("axes[2].unit"));
- }
+ });
+ assertTrue(e.getMessage().contains("axes[2].unit"));
}
/**
@@ -63,11 +59,30 @@ public final class ArgumentChecksTest extends TestCase {
@Test
public void testEnsureBetweenAndDistinct() {
ArgumentChecks.ensureNonEmptyBounded("dimensions", true, 0, 4, new
int[] {2, 3, 0, 1});
- try {
+ IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, () -> {
ArgumentChecks.ensureNonEmptyBounded("dimensions", true, 0, 4, new
int[] {2, 3, 3, 1});
- fail("Expected an IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- assertNotNull(e.getMessage());
- }
+ });
+ assertNotNull(e.getMessage());
+ }
+
+ /**
+ * Tests {@link ArgumentChecks#ensurePositive(java.lang.String, double)}.
+ */
+ @Test
+ public void testEnsurePositive() {
+ ArgumentChecks.ensurePositive("length", 4d);
+ ArgumentChecks.ensurePositive("length", 0d);
+ IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, () -> {
+ ArgumentChecks.ensurePositive("length", -4d);
+ });
+ assertTrue(e.getMessage().contains("length"));
+ e = assertThrows(IllegalArgumentException.class, () -> {
+ ArgumentChecks.ensurePositive("length", -0d);
+ });
+ assertTrue(e.getMessage().contains("length"));
+ e = assertThrows(IllegalArgumentException.class, () -> {
+ ArgumentChecks.ensurePositive("length", -0f);
+ });
+ assertTrue(e.getMessage().contains("length"));
}
}
diff --git a/incubator/build.gradle.kts b/incubator/build.gradle.kts
index d78d2f957e..86cec2320e 100644
--- a/incubator/build.gradle.kts
+++ b/incubator/build.gradle.kts
@@ -48,6 +48,7 @@ dependencies {
// Test dependencies
testImplementation(tests.geoapi)
+ testImplementation(tests.junit5)
testImplementation(tests.junit4)
testRuntimeOnly (tests.junit)
testRuntimeOnly (tests.junitLauncher)
@@ -82,7 +83,7 @@ tasks.compileJava {
}
tasks.compileTestJava {
srcDir.list().forEach {
- addRead(options.compilerArgs, it,
"org.apache.sis.test.incubator,junit")
+ addRead(options.compilerArgs, it,
"org.apache.sis.test.incubator,org.junit.jupiter.api,junit")
}
}
diff --git a/incubator/src/org.apache.sis.test.incubator/test/module-info.java
b/incubator/src/org.apache.sis.test.incubator/test/module-info.java
index 5cea0f2dc5..62dcaa90b5 100644
--- a/incubator/src/org.apache.sis.test.incubator/test/module-info.java
+++ b/incubator/src/org.apache.sis.test.incubator/test/module-info.java
@@ -23,5 +23,7 @@
* @since 1.4
*/
module org.apache.sis.test.incubator {
+ requires transitive junit;
+ requires transitive org.junit.jupiter.api;
requires transitive org.opengis.geoapi.conformance;
}
diff --git a/netbeans-project/ivy.xml b/netbeans-project/ivy.xml
index 6aaa72c5d8..01c97e7812 100644
--- a/netbeans-project/ivy.xml
+++ b/netbeans-project/ivy.xml
@@ -27,6 +27,7 @@
<dependency org="jakarta.servlet" name="jakarta.servlet-api"
rev="6.0.0"/>
<dependency org="org.osgi" name="osgi.core"
rev="8.0.0"/>
<dependency org="org.junit.platform"
name="junit-platform-launcher" rev="1.9.3"/>
+ <dependency org="org.junit.jupiter" name="junit-jupiter-api"
rev="5.9.3"/>
<dependency org="org.junit.vintage" name="junit-vintage-engine"
rev="5.9.3"/>
<dependency org="junit" name="junit"
rev="4.13.2"/>
<dependency org="org.apache.derby" name="derby"
rev="10.15.2.0"/>
diff --git a/netbeans-project/nbproject/project.properties
b/netbeans-project/nbproject/project.properties
index c79b5b9019..bf7bf3c472 100644
--- a/netbeans-project/nbproject/project.properties
+++ b/netbeans-project/nbproject/project.properties
@@ -77,29 +77,30 @@ modules.list = org.apache.sis.cloud.aws,\
org.apache.sis.storage.sql,\
org.apache.sis.storage.xml,\
org.apache.sis.util
-read.options = --add-reads org.apache.sis.cloud.aws=junit \
- --add-reads org.apache.sis.console=junit \
- --add-reads org.apache.sis.feature=junit \
- --add-reads org.apache.sis.metadata=junit \
- --add-reads org.apache.sis.openoffice=junit \
- --add-reads org.apache.sis.portrayal=junit \
- --add-reads org.apache.sis.profile.france=junit \
- --add-reads org.apache.sis.profile.japan=junit \
- --add-reads org.apache.sis.referencing=junit \
- --add-reads org.apache.sis.referencing.gazetteer=junit \
- --add-reads org.apache.sis.storage=junit \
- --add-reads org.apache.sis.storage.earthobservation=junit \
- --add-reads org.apache.sis.storage.geotiff=junit \
- --add-reads org.apache.sis.storage.netcdf=junit \
- --add-reads org.apache.sis.storage.sql=junit \
- --add-reads org.apache.sis.storage.xml=junit \
- --add-reads org.apache.sis.util=junit
+read.options = --add-reads
org.apache.sis.cloud.aws=org.junit.jupiter.api,junit \
+ --add-reads org.apache.sis.console=org.junit.jupiter.api,junit \
+ --add-reads org.apache.sis.feature=org.junit.jupiter.api,junit \
+ --add-reads org.apache.sis.metadata=org.junit.jupiter.api,junit
\
+ --add-reads
org.apache.sis.openoffice=org.junit.jupiter.api,junit \
+ --add-reads
org.apache.sis.portrayal=org.junit.jupiter.api,junit \
+ --add-reads
org.apache.sis.profile.france=org.junit.jupiter.api,junit \
+ --add-reads
org.apache.sis.profile.japan=org.junit.jupiter.api,junit \
+ --add-reads
org.apache.sis.referencing=org.junit.jupiter.api,junit \
+ --add-reads
org.apache.sis.referencing.gazetteer=org.junit.jupiter.api,junit \
+ --add-reads org.apache.sis.storage=org.junit.jupiter.api,junit \
+ --add-reads
org.apache.sis.storage.earthobservation=org.junit.jupiter.api,junit \
+ --add-reads
org.apache.sis.storage.geotiff=org.junit.jupiter.api,junit \
+ --add-reads
org.apache.sis.storage.netcdf=org.junit.jupiter.api,junit \
+ --add-reads
org.apache.sis.storage.sql=org.junit.jupiter.api,junit \
+ --add-reads
org.apache.sis.storage.xml=org.junit.jupiter.api,junit \
+ --add-reads org.apache.sis.util=org.junit.jupiter.api,junit
test.options = --add-modules jama,GeographicLib.Java,\
com.h2database,\
org.hsqldb,\
org.apache.derby.tools,\
software.amazon.awssdk.utils,\
org.opengis.geoapi.conformance,\
+ org.junit.jupiter.api,\
${modules.list} \
--add-exports
org.apache.sis.util/org.apache.sis.test=${modules.list} \
--add-exports
org.apache.sis.metadata/org.apache.sis.test.xml=${modules.list} \
diff --git a/optional/build.gradle.kts b/optional/build.gradle.kts
index f77fbd58d7..27d33fd534 100644
--- a/optional/build.gradle.kts
+++ b/optional/build.gradle.kts
@@ -64,6 +64,7 @@ dependencies {
// Test dependencies
testImplementation(tests.geoapi)
+ testImplementation(tests.junit5)
testImplementation(tests.junit4)
testRuntimeOnly (tests.junit)
testRuntimeOnly (tests.junitLauncher)
@@ -81,7 +82,7 @@ tasks.compileJava {
tasks.compileTestJava {
patchForTests(options.compilerArgs);
srcDir.list().forEach {
- addRead(options.compilerArgs, it, "org.apache.sis.test.optional,junit")
+ addRead(options.compilerArgs, it,
"org.apache.sis.test.optional,org.junit.jupiter.api,junit")
}
}
diff --git a/optional/src/org.apache.sis.test.optional/test/module-info.java
b/optional/src/org.apache.sis.test.optional/test/module-info.java
index dcdcaaddf8..bb74d69566 100644
--- a/optional/src/org.apache.sis.test.optional/test/module-info.java
+++ b/optional/src/org.apache.sis.test.optional/test/module-info.java
@@ -23,5 +23,7 @@
* @since 1.4
*/
module org.apache.sis.test.optional {
+ requires transitive junit;
+ requires transitive org.junit.jupiter.api;
requires transitive org.opengis.geoapi.conformance;
}
diff --git a/settings.gradle.kts b/settings.gradle.kts
index d01052eca5..152fff8b2a 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -70,6 +70,7 @@ dependencyResolutionManagement {
create("tests") {
library("geoapi", "org.opengis",
"geoapi-conformance") .version {strictly(geoapiVersion)}
library("junit4", "junit", "junit")
.version {strictly("4.13.2")}
+ library("junit5", "org.junit.jupiter",
"junit-jupiter-api") .version {strictly("5.9.3")}
library("junit", "org.junit.vintage",
"junit-vintage-engine") .version {strictly("5.9.3")}
library("junitLauncher", "org.junit.platform",
"junit-platform-launcher").version {strictly("1.9.3")}
library("jama", "gov.nist.math", "jama")
.version {strictly("1.0.3")}