Skip to content

Commit

Permalink
Enable running tests in JDKs != 8
Browse files Browse the repository at this point in the history
This required adding removing dependencies in packages that were removed in JDK9 and later.
  • Loading branch information
rgallardo-netflix committed Aug 31, 2023
1 parent 74594e8 commit c4fcbd2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions archaius2-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Type, TypeConverter<?>> converters;

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,19 @@
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
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);

Expand Down Expand Up @@ -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"));
}
}
1 change: 1 addition & 0 deletions archaius2-persisted2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit c4fcbd2

Please sign in to comment.