InvalidEventException extends EventException implements MessageInvalid { public static InvalidEventException onConstraintViolations(EventMessage eventMsg, Iterable<ConstraintViolation> violations) { Factory factory = new Factory(eventMsg, violations); return factory.newException(); } private  InvalidEventException(String messageText, EventMessage eventMsg, Error error); static InvalidEventException onConstraintViolations(EventMessage eventMsg,
                                                 Iterable<ConstraintViolation> violations);  }
@Test @DisplayName("create exception with violations") void createWithViolations() { EventMessage msg = ProjectCreated.getDefaultInstance(); InvalidEventException exception = InvalidEventException.onConstraintViolations( msg, singletonList(ConstraintViolation.getDefaultInstance())); assertNotNull(exception.getMessage()); assertNotNull(exception.asError()); assertEquals(msg, exception.getEventMessage()); }