EnvelopeValidationExceptionHandlerProducer { @Produces public EnvelopeValidationExceptionHandler envelopeValidationExceptionHandler() { try { final Class<?> clazz = Class.forName(handlerClass); return (EnvelopeValidationExceptionHandler) clazz.newInstance(); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { throw new IllegalArgumentException("Could not instantiate validation exception handler.", e); } }  @Produces EnvelopeValidationExceptionHandler envelopeValidationExceptionHandler();  }
@Test public void shouldProduceRethrowingHandler() { producer.handlerClass = "uk.gov.justice.services.core.envelope.RethrowingValidationExceptionHandler"; assertThat(producer.envelopeValidationExceptionHandler(), instanceOf(RethrowingValidationExceptionHandler.class)); }
@Test public void shouldProduceLoggingHandler() { producer.handlerClass = "uk.gov.justice.services.core.envelope.LoggingValidationExceptionHandler"; assertThat(producer.envelopeValidationExceptionHandler(), instanceOf(LoggingValidationExceptionHandler.class)); }
@Test public void shouldThrowExceptionIfClassDoesNotExist() { producer.handlerClass = "uk.gov.justice.services.core.envelope.NonExisting"; exception.expect(IllegalArgumentException.class); exception.expectMessage("Could not instantiate validation exception handler."); producer.envelopeValidationExceptionHandler(); }