MavenConfigurationExtractor { public static Map<String, Object> extract(Xpp3Dom root) { if (root == null) { return new HashMap<>(); } return getElement(root); } private  MavenConfigurationExtractor(); static Map<String, Object> extract(Xpp3Dom root);  }
@Test public void should_parse_simple_types() { final Plugin fakePlugin = createFakePlugin("<a>a</a><b>b</b>"); final Map<String, Object> config = MavenConfigurationExtractor.extract((Xpp3Dom) fakePlugin.getConfiguration()); assertThat(config) .containsEntry("a", "a") .containsEntry("b", "b"); }
@Test public void should_parse_inner_objects() { final Plugin fakePlugin = createFakePlugin("<a>" + "<b>b</b>" + "</a>"); final Map<String, Object> config = MavenConfigurationExtractor.extract((Xpp3Dom) fakePlugin.getConfiguration()); final Map<String, Object> expected = new HashMap<>(); expected.put("b", "b"); assertThat(config) .containsEntry("a", expected); }
@Test public void should_parse_deep_inner_objects() { final Plugin fakePlugin = createFakePlugin("<a>" + "<b>" + "<c>" + "<d>" + "<e>e1</e>" + "</d>" + "</c>" + "</b>" + "</a>"); final Map<String, Object> config = MavenConfigurationExtractor.extract((Xpp3Dom) fakePlugin.getConfiguration()); final Map<String, Object> e = new HashMap<>(); e.put("e", "e1"); final Map<String, Object> d = new HashMap<>(); d.put("d", e); final Map<String, Object> c = new HashMap<>(); c.put("c", d); final Map<String, Object> expected = new HashMap<>(); expected.put("b", c); assertThat(config) .containsEntry("a", expected); }
@Test public void should_parse_list_of_elements() { final Plugin fakePlugin = createFakePlugin("<a>" + "<b>" + "<c>c1</c><c>c2</c>" + "</b>" + "</a>"); final Map<String, Object> config = MavenConfigurationExtractor.extract((Xpp3Dom) fakePlugin.getConfiguration()); final Map<String, Object> expectedC = new HashMap<>(); expectedC.put("c", Arrays.asList("c1", "c2")); final Map<String, Object> expected = new HashMap<>(); expected.put("b", expectedC); assertThat(config) .containsEntry("a",expected); }
@Test public void should_parse_list_of_mixed_elements() { final Plugin fakePlugin = createFakePlugin("<a>" + "<b>" + "<c>c1</c><d>d1</d><c>c2</c>" + "</b>" + "</a>"); final Map<String, Object> config = MavenConfigurationExtractor.extract((Xpp3Dom) fakePlugin.getConfiguration()); final Map<String, Object> expectedC = new HashMap<>(); expectedC.put("c", Arrays.asList("c1", "c2")); expectedC.put("d", "d1"); final Map<String, Object> expected = new HashMap<>(); expected.put("b", expectedC); assertThat(config) .containsEntry("a",expected); }