aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenning Schmiedehausen <henning@schmiedehausen.org>2021-03-02 12:11:22 -0800
committerHenning Schmiedehausen <henning@schmiedehausen.org>2021-03-02 12:11:22 -0800
commit7a3fbd52f480fd29f184039807c3dab2a24f050a (patch)
tree98a1926868124148edae1d1a1c1481374b2076f2
parenta9c3432f357b62370992d4698a2f78c97cf484cb (diff)
downloadapache-velocity-engine-7a3fbd52f480fd29f184039807c3dab2a24f050a.tar.gz
Fixes failing tests on JDK 11+
Some brittle code tests the messages of exceptions etc. in the tests which have changed in JDK11+ Tested with OpenJDK 11 and OpenJDK 15.
-rw-r--r--velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java30
-rw-r--r--velocity-engine-core/src/test/java/org/apache/velocity/test/issues/VelTools66TestCase.java8
-rw-r--r--velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ConversionHandlerTestCase.java10
3 files changed, 41 insertions, 7 deletions
diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java b/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java
index 63e10676..c415e476 100644
--- a/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java
+++ b/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java
@@ -472,27 +472,45 @@ public class BuiltInEventHandlerTestCase extends BaseTestCase {
ve1.evaluate(context, writer, "test", "$list.get(0)");
String result = writer.toString();
assertTrue(result.contains("IndexOutOfBoundsException"));
- assertTrue(result.contains("Index: 0, Size: 0"));
+ assertTrue(
+ result.contains("Index: 0, Size: 0") // JDK8
+ || result.contains("Index 0 out of bounds for length 0") // JDK 11 / JDK 15
+ );
assertTrue(!result.contains("at test (line 1, column 7)"));
- assertTrue(!result.contains("rangeCheck"));
+ assertFalse(
+ result.contains("rangeCheck") // JDK 8
+ || result.contains("Preconditions.outOfBounds") // JDK 11 / JDK 15
+ );
// exception, message and template info
writer = new StringWriter();
ve2.evaluate(context,writer,"test","$list.get(0)");
result = writer.toString();
assertTrue(result.contains("IndexOutOfBoundsException"));
- assertTrue(result.contains("Index: 0, Size: 0"));
+ assertTrue(
+ result.contains("Index: 0, Size: 0") // JDK8
+ || result.contains("Index 0 out of bounds for length 0") // JDK 11 / JDK 15
+ );
assertTrue(result.contains("at test (line 1, column 7)"));
- assertTrue(!result.contains("rangeCheck"));
+ assertFalse(
+ result.contains("rangeCheck") // JDK 8
+ || result.contains("Preconditions.outOfBounds") // JDK 11 / JDK 15
+ );
// exception, message and stack trace
writer = new StringWriter();
ve3.evaluate(context,writer,"test","$list.get(0)");
result = writer.toString();
assertTrue(result.contains("IndexOutOfBoundsException"));
- assertTrue(result.contains("Index: 0, Size: 0"));
+ assertTrue(
+ result.contains("Index: 0, Size: 0") // JDK8
+ || result.contains("Index 0 out of bounds for length 0") // JDK 11 / JDK 15
+ );
assertTrue(!result.contains("at test (line 1, column 7)"));
- assertTrue(result.contains("rangeCheck"));
+ assertTrue(
+ result.contains("rangeCheck") // JDK 8
+ || result.contains("Preconditions.outOfBounds") // JDK 11 / JDK 15
+ );
log("PrintException handler successful.");
diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/VelTools66TestCase.java b/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/VelTools66TestCase.java
index 3906f6c2..529683ff 100644
--- a/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/VelTools66TestCase.java
+++ b/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/VelTools66TestCase.java
@@ -83,7 +83,13 @@ public class VelTools66TestCase
/* the testcase is obsolete in JDK 8, as SystemManager.checkMemberAccess is not anymore called
* by Class.getMethods() */
- int javaVersion = Integer.parseInt(System.getProperty("java.version").split("\\.")[1]);
+ String [] javaVersionFields = System.getProperty("java.version").split("\\.");
+ int javaVersion = Integer.parseInt(javaVersionFields[0]);
+ if (javaVersion == 1)
+ {
+ javaVersion = Integer.parseInt(javaVersionFields[1]);
+ }
+
if (javaVersion >= 8)
{
return;
diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ConversionHandlerTestCase.java b/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ConversionHandlerTestCase.java
index a006a547..c15b18fc 100644
--- a/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ConversionHandlerTestCase.java
+++ b/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ConversionHandlerTestCase.java
@@ -305,6 +305,16 @@ public class ConversionHandlerTestCase extends BaseTestCase
Exception e,
Info info)
{
+ // JDK 11+ changed the exception message for big decimal conversion exceptions,
+ // which breaks the (brittle) tests. Clearly, it would be preferred to fix this
+ // right by comparing the result according to the JDK version, this is just a
+ // quick fix to get the build to pass on JDK 11+
+ //
+ if (e.getClass() == NumberFormatException.class && e.getMessage() != null && e.getMessage().startsWith("Character"))
+ {
+ return method + " -> " + e.getClass().getSimpleName() + ": null"; // compatible with JDK8
+ }
+
return method + " -> " + e.getClass().getSimpleName() + ": " + e.getMessage();
}
}