### Question:
ExceptionHandlingProcessorDecorator extends ProcessorDecorator { @Override public void process(final Resource resource, final Reader reader, final Writer writer) throws IOException { final String resourceContent = IOUtils.toString(reader); final Reader innerReader = new StringReader(resourceContent); final StringWriter innerWriter = new StringWriter(); try { super.process(resource, innerReader, innerWriter); writer.write(innerWriter.toString()); } catch (final Exception e) { final String processorName = toString(); if (isIgnoreFailingProcessor()) { LOG.debug("Ignoring failed processor. Original Exception", e); writer.write(resourceContent); } else { LOG.error("Failed to process the resource: {} using processor: {}. Reason: {}", resource, processorName, e.getMessage()); final String resourceUri = resource != null ? resource.getUri() : null; throw WroRuntimeException.wrap(e, "The processor: " + processorName + " faile while processing uri: " + resourceUri).setResource(resource); } } finally { reader.close(); writer.close(); } } ExceptionHandlingProcessorDecorator(final Object processor); @Override void process(final Resource resource, final Reader reader, final Writer writer);  }### Answer:
@Test public void shouldInvokeDecoratedProcessor() throws Exception { mockProcessor = Mockito.spy(new JSMinProcessor()); victim = new ExceptionHandlingProcessorDecorator(mockProcessor); WroTestUtils.createInjector().inject(victim); final String resourceContent = "alert( 1 );"; final StringWriter writer = new StringWriter(); final Reader reader = new StringReader(resourceContent); victim.process(mockResource, reader, writer); Mockito.verify(mockProcessor).process(Mockito.any(Resource.class), Mockito.any(Reader.class), Mockito.any(Writer.class)); Assert.assertEquals("\nalert(1);", writer.toString()); }
@Test(expected = WroRuntimeException.class) public void shouldThrowRuntimeExceptionWhenProcessingFails() throws Exception { Mockito.doThrow(new IOException("BOOM")).when(mockProcessor).process(Mockito.any(Resource.class), Mockito.any(Reader.class), Mockito.any(Writer.class)); victim.process(mockResource, new StringReader(""), new StringWriter()); }
@Test public void shouldPreserveContentWhenProcessingFails() throws Exception { Context.get().getConfig().setIgnoreFailingProcessor(true); Mockito.doThrow(new IOException("BOOM")).when(mockProcessor).process(Mockito.any(Resource.class), Mockito.any(Reader.class), Mockito.any(Writer.class)); final String resourceContent = "alert(1);"; final StringWriter writer = new StringWriter(); final Reader reader = new StringReader(resourceContent); victim.process(mockResource, reader, writer); Mockito.verify(mockProcessor).process(Mockito.any(Resource.class), Mockito.any(Reader.class), Mockito.any(Writer.class)); Assert.assertEquals(resourceContent, writer.toString()); }