ValidationWrapper { public void check(Map<Path, Node> fileNodeMap) { AtomicReference<Node> previousNodes = new AtomicReference<>(); AtomicReference<Path> previousPathRef = new AtomicReference<>(); fileNodeMap.forEach((path, node) -> { validate(validator, (Element) node, path); if (previousNodes.get() != null) { compare(validator, (Element) node, (Element) previousNodes.get(), path, previousPathRef.get()); } previousNodes.set(node); previousPathRef.set(path); }); } ValidationWrapper(ConfigValidator configValidator); void check(Map<Path, Node> fileNodeMap); void validate(ConfigValidator validator, Element element, Path path);  }
@Test public void testCheck() throws ValidationException { ConfigValidator validator = mock(ConfigValidator.class); ValidationWrapper validationWrapper = new ValidationWrapper(validator); ValidationWrapper spyValidationWrapper = Mockito.spy(validationWrapper); Map<Path, Node> param = new HashMap<>(); Path path1 = mock(Path.class); Element element1 = mock(Element.class); param.put(path1, element1); Path path2 = mock(Path.class); Element element2 = mock(Element.class); param.put(path2, element2); Path path3 = mock(Path.class); Element element3 = mock(Element.class); param.put(path3, element3); doNothing().when(validator).validate(element1); doNothing().when(validator).validate(element2); doNothing().when(validator).validate(element3); doNothing().when(validator).validateAgainst(element2, element1); doNothing().when(validator).validateAgainst(element3, element2); ArgumentCaptor<Element> elementArgumentCaptor1 = ArgumentCaptor.forClass(Element.class); ArgumentCaptor<Element> elementArgumentCaptor2 = ArgumentCaptor.forClass(Element.class); ArgumentCaptor<Element> elementArgumentCaptor3 = ArgumentCaptor.forClass(Element.class); spyValidationWrapper.check(param); verify(validator, times(3)).validate(elementArgumentCaptor1.capture()); verify(validator, times(2)).validateAgainst(elementArgumentCaptor2.capture(), elementArgumentCaptor3.capture()); assertThat(elementArgumentCaptor1.getAllValues() .containsAll(Arrays.asList(element1, element2, element3)), is(true)); List<Element> invokedElementParamList = new ArrayList<>(); invokedElementParamList.addAll(elementArgumentCaptor2.getAllValues()); invokedElementParamList.addAll(elementArgumentCaptor3.getAllValues()); assertThat(invokedElementParamList.containsAll(Arrays.asList(element3, element2, element1)), is(true)); }