### Question:
DatabaseValidator { public ValidationResult check() { GraphTraversal<Vertex, Vertex> traversal = graphManager.getGraph().traversal().V(); List<ValidationResult> validationResults = Lists.newArrayList(); for (DatabaseCheck databaseCheck : databaseChecks) { databaseCheck.init(graphManager.getGraph(), graphManager.getGraphDatabase()); } while (traversal.hasNext()) { Vertex vertex = traversal.next(); for (DatabaseCheck databaseCheck : databaseChecks) { validationResults.add(databaseCheck.check(vertex)); } } for (DatabaseCheck databaseCheck : databaseChecks) { databaseCheck.finish(); } return new CompositeValidationResult(validationResults); } DatabaseValidator(TinkerPopGraphManager graphManager, DatabaseCheck... databaseChecks); ValidationResult check();  }### Answer:
@Test public void checkCallsInitAndFinish() { TinkerPopGraphManager graph = makeGraph("1"); DatabaseCheck databaseCheck1 = mock(DatabaseCheck.class); DatabaseCheck databaseCheck2 = mock(DatabaseCheck.class); DatabaseValidator instance = new DatabaseValidator(graph, databaseCheck1, databaseCheck2); instance.check(); InOrder inOrder = inOrder(databaseCheck1, databaseCheck2); inOrder.verify(databaseCheck1).init(any(Graph.class), any(GraphDatabaseService.class)); inOrder.verify(databaseCheck2).init(any(Graph.class), any(GraphDatabaseService.class)); inOrder.verify(databaseCheck1).check(any(Vertex.class)); inOrder.verify(databaseCheck2).check(any(Vertex.class)); inOrder.verify(databaseCheck1).finish(); inOrder.verify(databaseCheck2).finish(); }
@Test public void checkRunsAllTheDatabaseChecksForEachVertex() { String id1 = "id1"; String id2 = "id2"; TinkerPopGraphManager graph = makeGraph(id1, id2); DatabaseCheck databaseCheck1 = mock(DatabaseCheck.class); DatabaseCheck databaseCheck2 = mock(DatabaseCheck.class); DatabaseValidator instance = new DatabaseValidator(graph, databaseCheck1, databaseCheck2); instance.check(); verify(databaseCheck1).check(argThat(likeVertex().withTimId(id1))); verify(databaseCheck1).check(argThat(likeVertex().withTimId(id2))); verify(databaseCheck2).check(argThat(likeVertex().withTimId(id1))); verify(databaseCheck2).check(argThat(likeVertex().withTimId(id2))); }
@Test public void checkReturnsTheValidationResult() { TinkerPopGraphManager graph = makeGraph("id1", "id2"); DatabaseValidator instance = new DatabaseValidator(graph); ValidationResult result = instance.check(); assertThat(result, is(notNullValue())); }
@Test public void checkReturnsANonValidValidationResultWhenAtLeastOneOfTheChecksFails() { TinkerPopGraphManager graph = makeGraph("id1", "id2"); DatabaseValidator instance = new DatabaseValidator(graph, nonValidDatabaseCheck()); ValidationResult validationResult = instance.check(); assertThat(validationResult.isValid(), is(false)); }
@Test public void checkReturnsAValidValidationResultWhenAllOfTheChecksSucceed() { TinkerPopGraphManager graph = makeGraph("id", "id2"); DatabaseValidator instance = new DatabaseValidator(graph, validDatabaseCheck()); ValidationResult result = instance.check(); assertThat(result.isValid(), is(true)); }