You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2019/05/13 05:31:29 UTC
[logging-log4j2] 04/06: Delegate method call to make it testable
(without having to use reflection).
This is an automated email from the ASF dual-hosted git repository.
rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 16fa74e9c6ffba32246b70649140b4cfcabe7ee5
Author: ulrichenslin <ue...@apple.com>
AuthorDate: Mon Mar 4 08:22:19 2019 +0200
Delegate method call to make it testable (without having to use reflection).
---
.../org/apache/logging/log4j/util/Constants.java | 5 ++++-
.../org/apache/logging/log4j/util/ConstantsTest.java | 20 ++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
index c0d18d7..2fc67f4 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
@@ -89,7 +89,10 @@ public final class Constants {
}
private static int getMajorVersion() {
- final String version = System.getProperty("java.version");
+ return getMajorVersion(System.getProperty("java.version"));
+ }
+
+ static int getMajorVersion(final String version) {
final String[] parts = version.split("-|\\.");
boolean isJEP223;
try {
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/ConstantsTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/ConstantsTest.java
new file mode 100644
index 0000000..f568c9f
--- /dev/null
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/ConstantsTest.java
@@ -0,0 +1,20 @@
+package org.apache.logging.log4j.util;
+
+import org.junit.Test;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class ConstantsTest {
+
+ @Test
+ public void testJdkVersionDetection() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ assertEquals(1, Constants.getMajorVersion("1.1.2"));
+ assertEquals(8, Constants.getMajorVersion("1.8.2"));
+ assertEquals(9, Constants.getMajorVersion("9.1.1"));
+ assertEquals(11, Constants.getMajorVersion("11.1.1"));
+ }
+}
\ No newline at end of file