### Question:
CanvasDiagramValidator { @SuppressWarnings("unchecked") public void validate(final H canvasHandler, final Consumer<Collection<DiagramElementViolation<RuleViolation>>> callback) { diagramValidator.validate(canvasHandler.getDiagram(), violations -> { checkViolations(canvasHandler, violations); callback.accept(violations); }); } protected  CanvasDiagramValidator(); @Inject  CanvasDiagramValidator(final DiagramValidator<Diagram, RuleViolation> diagramValidator,
                                  final Event<CanvasValidationSuccessEvent> validationSuccessEvent,
                                  final Event<CanvasValidationFailEvent> validationFailEvent); @SuppressWarnings("unchecked") void validate(final H canvasHandler,
                         final Consumer<Collection<DiagramElementViolation<RuleViolation>>> callback);  }### Answer:
@Test @SuppressWarnings("unchecked") public void validateSuccess() { when(domainViolation.getViolationType()).thenReturn(Violation.Type.INFO); when(ruleViolation.getViolationType()).thenReturn(Violation.Type.INFO); when(modelViolation.getViolationType()).thenReturn(Violation.Type.INFO); ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); ArgumentCaptor<CanvasValidationSuccessEvent> captorEvent = ArgumentCaptor.forClass(CanvasValidationSuccessEvent.class); tested.validate(canvasHandler, callback); verify(diagramValidator).validate(eq(diagram), captor.capture()); captor.getValue().accept(violations); verify(callback).accept(violations); verify(successEvent).fire(captorEvent.capture()); CanvasValidationSuccessEvent event = captorEvent.getValue(); assertEquals(event.getDiagramName(), NAME); assertEquals(event.getDiagramTitle(), TITLE); }
@Test @SuppressWarnings("unchecked") public void validateSuccessNoElementViolations() { final ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); final ArgumentCaptor<CanvasValidationSuccessEvent> captorEvent = ArgumentCaptor.forClass(CanvasValidationSuccessEvent.class); violations = Collections.emptyList(); tested.validate(canvasHandler, callback); verify(diagramValidator).validate(eq(diagram), captor.capture()); captor.getValue().accept(violations); verify(callback).accept(violations); verify(successEvent).fire(captorEvent.capture()); CanvasValidationSuccessEvent event = captorEvent.getValue(); assertEquals(event.getDiagramName(), NAME); assertEquals(event.getDiagramTitle(), TITLE); }
@Test @SuppressWarnings("unchecked") public void validateSuccessNoDomainGraphModelViolations() { final ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); final ArgumentCaptor<CanvasValidationSuccessEvent> captorEvent = ArgumentCaptor.forClass(CanvasValidationSuccessEvent.class); reset(violation); when(violation.getUUID()).thenReturn(UUID); when(violation.getDomainViolations()).thenReturn(Collections.emptyList()); when(violation.getGraphViolations()).thenReturn(Collections.emptyList()); when(violation.getModelViolations()).thenReturn(Collections.emptyList()); tested.validate(canvasHandler, callback); verify(diagramValidator).validate(eq(diagram), captor.capture()); captor.getValue().accept(violations); verify(callback).accept(violations); verify(successEvent).fire(captorEvent.capture()); CanvasValidationSuccessEvent event = captorEvent.getValue(); assertEquals(event.getDiagramName(), NAME); assertEquals(event.getDiagramTitle(), TITLE); }