Skip to content

Commit

Permalink
Year conversion tests completed. Updated test harness to support runn…
Browse files Browse the repository at this point in the history
…ing a single test. Fixed the extractSingleKey MapConversion.
  • Loading branch information
jdereg committed Feb 5, 2024
1 parent 333c083 commit 6040524
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private static <T> T fromSingleKey(final Object from, final Converter converter,
Map<?, ?> map = asMap(from);

if (map.containsKey(key)) {
return converter.convert(key, type, options);
return converter.convert(map.get(key), type, options);
}

return extractValue(map, converter, options, type, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,12 @@ class ConverterEverythingTest
TEST_FACTORY.put(pair(Map.class, Year.class), new Object[][] {
{ mapOf("_v", "1984"), Year.of(1984) },
{ mapOf("value", 1984L), Year.of(1984) },
// { mapOf("year", 1992), Year.of(1992) },
// { mapOf("year", mapOf("_v", (short)2024)), Year.of(2024) }, // recursion
});
// DEFAULT_FACTORY.put(pair(Void.class, Year.class), VoidConversions::toNull);
// DEFAULT_FACTORY.put(pair(Year.class, Year.class), Converter::identity);
// DEFAULT_FACTORY.put(pair(Byte.class, Year.class), UNSUPPORTED);
// DEFAULT_FACTORY.put(pair(Number.class, Year.class), NumberConversions::toYear);
// DEFAULT_FACTORY.put(pair(String.class, Year.class), StringConversions::toYear);
// DEFAULT_FACTORY.put(pair(Map.class, Year.class), MapConversions::toYear);
{ mapOf("year", 1492), Year.of(1492) },
{ mapOf("year", mapOf("_v", (short)2024)), Year.of(2024) }, // recursion
});
TEST_FACTORY.put(pair(Number.class, Year.class), new Object[][] {
{ (byte)101, new IllegalArgumentException("Unsupported conversion, source type [Byte (101)] target type 'Year'") },
});
}

@BeforeEach
Expand All @@ -355,6 +352,10 @@ void testEverything() {
Map<Class<?>, Set<Class<?>>> map = converter.allSupportedConversions();
int neededTests = 0;
int count = 0;
boolean runOnlyOneTest = false;
Class<?> singleSource = Number.class;
Class<?> singleTarget = Year.class;
int singleIndex = 0;

for (Map.Entry<Class<?>, Set<Class<?>>> entry : map.entrySet()) {
Class<?> sourceClass = entry.getKey();
Expand All @@ -372,6 +373,12 @@ void testEverything() {
}

for (int i=0; i < testData.length; i++) {
if (runOnlyOneTest) {
if (!sourceClass.equals(singleSource) || !targetClass.equals(singleTarget) || singleIndex != i) {
continue;
}
}

Object[] testPair = testData[i];
try {
verifyTestPair(sourceClass, targetClass, testPair);
Expand Down

0 comments on commit 6040524

Please sign in to comment.