From c4fcbd2f1838be4e4dd1450a65c46c3a769301bb Mon Sep 17 00:00:00 2001 From: Rebeca Gallardo Date: Thu, 31 Aug 2023 11:36:31 -0700 Subject: [PATCH] Enable running tests in JDKs != 8 This required adding removing dependencies in packages that were removed in JDK9 and later. --- archaius2-core/build.gradle | 1 + .../converters/DefaultTypeConverterFactory.java | 15 ++++++++++++--- .../com/netflix/archaius/DefaultDecoderTest.java | 11 +++++------ archaius2-persisted2/build.gradle | 1 + build.gradle | 8 ++++++++ 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/archaius2-core/build.gradle b/archaius2-core/build.gradle index 1fcb1b00d..a11fec656 100644 --- a/archaius2-core/build.gradle +++ b/archaius2-core/build.gradle @@ -20,6 +20,7 @@ dependencies { api project(':archaius2-api') implementation 'org.slf4j:slf4j-api:1.7.36' implementation 'org.apache.commons:commons-lang3:3.3.2' + implementation 'commons-codec:commons-codec:1.16.0' testImplementation 'com.google.code.findbugs:jsr305:3.0.1' } diff --git a/archaius2-core/src/main/java/com/netflix/archaius/converters/DefaultTypeConverterFactory.java b/archaius2-core/src/main/java/com/netflix/archaius/converters/DefaultTypeConverterFactory.java index 21a3e8be9..e08d9d1f2 100644 --- a/archaius2-core/src/main/java/com/netflix/archaius/converters/DefaultTypeConverterFactory.java +++ b/archaius2-core/src/main/java/com/netflix/archaius/converters/DefaultTypeConverterFactory.java @@ -2,8 +2,9 @@ import com.netflix.archaius.api.TypeConverter; import com.netflix.archaius.exceptions.ParseException; +import org.apache.commons.codec.DecoderException; +import org.apache.commons.codec.binary.Hex; -import javax.xml.bind.DatatypeConverter; import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.BigInteger; @@ -39,7 +40,7 @@ else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("no") || valu return Boolean.FALSE; } throw new ParseException("Error parsing value '" + value + "'", new Exception("Expected one of [true, yes, on, false, no, off]")); - }; + } private final Map> converters; @@ -75,7 +76,15 @@ private DefaultTypeConverterFactory() { converters.put(Instant.class, v -> Instant.from(OffsetDateTime.parse(v))); converters.put(Date.class, v -> new Date(Long.parseLong(v))); converters.put(Currency.class, Currency::getInstance); - converters.put(BitSet.class, v -> BitSet.valueOf(DatatypeConverter.parseHexBinary(v))); + + converters.put(BitSet.class, v -> { + try { + return BitSet.valueOf(Hex.decodeHex(v)); + } catch (DecoderException e) { + throw new RuntimeException(e); + } + }); + this.converters = Collections.unmodifiableMap(converters); } diff --git a/archaius2-core/src/test/java/com/netflix/archaius/DefaultDecoderTest.java b/archaius2-core/src/test/java/com/netflix/archaius/DefaultDecoderTest.java index ebd5045c3..346e39520 100644 --- a/archaius2-core/src/test/java/com/netflix/archaius/DefaultDecoderTest.java +++ b/archaius2-core/src/test/java/com/netflix/archaius/DefaultDecoderTest.java @@ -33,12 +33,11 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -import javax.xml.bind.DatatypeConverter; - +import org.apache.commons.codec.DecoderException; +import org.apache.commons.codec.binary.Hex; import org.junit.Assert; import org.junit.Test; -import com.netflix.archaius.DefaultDecoder; public class DefaultDecoderTest { @Test @@ -46,7 +45,7 @@ public void testJavaNumbers() { DefaultDecoder decoder = DefaultDecoder.INSTANCE; boolean flag = decoder.decode(boolean.class, "true"); - Assert.assertEquals(true, flag); + Assert.assertTrue(flag); int int_value = decoder.decode(int.class, "123"); Assert.assertEquals(123, int_value); @@ -80,10 +79,10 @@ public void testJavaDateTime() { } @Test - public void testJavaMiscellaneous() { + public void testJavaMiscellaneous() throws DecoderException { DefaultDecoder decoder = DefaultDecoder.INSTANCE; Assert.assertEquals(Currency.getInstance("USD"), decoder.decode(Currency.class, "USD")); - Assert.assertEquals(BitSet.valueOf(DatatypeConverter.parseHexBinary("DEADBEEF00DEADBEEF")), decoder.decode(BitSet.class, "DEADBEEF00DEADBEEF")); + Assert.assertEquals(BitSet.valueOf(Hex.decodeHex("DEADBEEF00DEADBEEF")), decoder.decode(BitSet.class, "DEADBEEF00DEADBEEF")); Assert.assertEquals("testString", decoder.decode(String.class, "testString")); } } diff --git a/archaius2-persisted2/build.gradle b/archaius2-persisted2/build.gradle index ab4bff6c3..c50f44c6c 100644 --- a/archaius2-persisted2/build.gradle +++ b/archaius2-persisted2/build.gradle @@ -20,6 +20,7 @@ dependencies { api project(':archaius2-core') implementation 'com.fasterxml.jackson.core:jackson-core:2.4.3' implementation 'com.fasterxml.jackson.core:jackson-databind:2.4.3' + implementation 'javax.annotation:javax.annotation-api:1.3.2' implementation 'org.apache.commons:commons-lang3:3.3.2' implementation 'org.slf4j:slf4j-api:1.7.36' diff --git a/build.gradle b/build.gradle index 9fde23cbc..cc3247cae 100644 --- a/build.gradle +++ b/build.gradle @@ -37,4 +37,12 @@ subprojects { tasks.withType(Javadoc) { options.addStringOption('Xdoclint:none', '-quiet') } + + tasks.withType(Test) { + var testJdk = System.getProperty("testJdk", "17") + System.console().printf("Launching tests using JDK %s%n", testJdk) + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(testJdk) + } + } }