Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable running tests in JDKs != 8 #672

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kilink , try pulling this change into your branch and run with

./gradlew  -DtestJdk=17 clean test

to run the tests under 17.
As of this change, I still have a bunch of failures, but they seem to mostly be related to dep mismatches with Mockito :-(

tasks.withType(Test) {
var testJdk = System.getProperty("testJdk", "8")
System.console().printf("Launching tests using JDK %s%n", testJdk)
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(testJdk)
}
}
}