MavenMetadataParser implements Function<String, Either<Throwable, Response>> { static List<String> extractItems(final NodeList nodeList) { return IntStream.range(0, nodeList.getLength()) .mapToObj(nodeList::item) .map(Node::getTextContent) .collect(toList()); } MavenMetadataParser(final String server);   MavenMetadataParser(final String server, final String groupId, final String artifactId);  MavenMetadataParser(); @Override Either<Throwable, Response> apply(final String newVersion);  }
@Test void parseSingleNodeList() { final String version = "1.2.3"; final Node n = mock(Node.class); when(n.getTextContent()).thenReturn(version); final NodeList l = mock(NodeList.class); when(l.getLength()).thenReturn(1); when(l.item(eq(0))).thenReturn(n); final List<String> actual = MavenMetadataParser.extractItems(l); assertThat(actual).containsExactly(version); }
@Test void parseLongerNodeList() { final String version = "1.2.3", version2 = "1.2.4-SNAPSHOT"; final Node n1 = mock(Node.class); when(n1.getTextContent()).thenReturn(version); final Node n2 = mock(Node.class); when(n2.getTextContent()).thenReturn(version2); final NodeList l = mock(NodeList.class); when(l.getLength()).thenReturn(2); when(l.item(eq(0))).thenReturn(n1); when(l.item(eq(1))).thenReturn(n2); final List<String> actual = MavenMetadataParser.extractItems(l); assertThat(actual).containsExactly(version, version2); }