Skip to content

Commit

Permalink
Add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akang31 committed Jan 15, 2025
1 parent d3d1171 commit 6d4bd30
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,37 @@ public void testInvalidInterface() {
containsString("getAnIntWithParam")));
}

@Test
public void testSpringYmlCollections() {
config.setProperty("list[0]", "1");
config.setProperty("list[1]", 2);
config.setProperty("list[2]", "3");

config.setProperty("set[0]", "1");
config.setProperty("set[1]", "2");
config.setProperty("set[2]", 3);
config.setProperty("set[3]", "3");

config.setProperty("map.key1", "1");
config.setProperty("map.key2", 2);
config.setProperty("map.key3", "3");

ConfigWithSpringCollections configWithSpringCollections = proxyFactory.newProxy(ConfigWithSpringCollections.class);
assertEquals(Arrays.asList("1", "2", "3"), configWithSpringCollections.getList());

Set<Integer> set = configWithSpringCollections.getSet();
assertEquals(3, set.size());
assertTrue(set.contains(1));
assertTrue(set.contains(2));
assertTrue(set.contains(3));

Map<String, Integer> map = configWithSpringCollections.getMap();
assertEquals(3, map.size());
assertEquals(1, map.get("key1"));
assertEquals(2, map.get("key2"));
assertEquals(3, map.get("key3"));
}


//////////////////////////////////////////////////////////////////
/// Test Interfaces
Expand Down Expand Up @@ -666,4 +697,10 @@ public interface ConfigWithBadSettings {
// A parametrized method requires a @PropertyName annotation
int getAnIntWithParam(String param);
}

public interface ConfigWithSpringCollections {
List<String> getList();
Set<Integer> getSet();
Map<String, Integer> getMap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public class AbstractConfigTest {
entries.put("springYmlList[0]", "1");
entries.put("springYmlList[1]", "2");
entries.put("springYmlList[2]", "3");
entries.put("springYmlIntList[0]", 1);
entries.put("springYmlIntList[1]", 2);
entries.put("springYmlIntList[2]", 3);
// Repeated entry to distinguish set and list
entries.put("springYmlList[3]", "3");
entries.put("springYmlMap.key1", "1");
Expand Down Expand Up @@ -246,6 +249,10 @@ public void testSpringYml() {
config.get(ArchaiusType.forListOf(Integer.class), "springYmlList", Arrays.asList(1));
assertEquals(Arrays.asList(1, 2, 3, 3), list);

List<Integer> intList =
config.get(ArchaiusType.forListOf(Integer.class), "springYmlIntList", Arrays.asList(1));
assertEquals(Arrays.asList(1, 2, 3), intList);

Map<String, Integer> map =
config.get(ArchaiusType.forMapOf(String.class, Integer.class),
"springYmlMap", Collections.emptyMap());
Expand Down Expand Up @@ -273,4 +280,13 @@ public void testSpringYml() {
assertEquals(1, invalidMap.size());
assertEquals("default", invalidMap.get("default"));
}

@Test
public void testSpringYamlAsNormalValue() {
// Confirm that values that are intended to be read as a Spring YML Map can still be read normally
// and also do not return values when read at the top level as anything other than a map.
assertEquals("1", config.get(String.class, "springYmlMap.key1"));
assertEquals(2, config.get(Integer.class, "springYmlMap.key2"));
assertEquals(false, config.containsKey("springYmlMap"));
}
}

0 comments on commit 6d4bd30

Please sign in to comment.