### Question:
ExceptionWrapper { public CheckStylePluginException wrap(@Nullable final String message, @NotNull final Throwable error) { final Throwable root = rootOrCheckStyleException(error); final String exMessage = ofNullable(message).orElseGet(root::getMessage); if (isParseException(root)) { return new CheckStylePluginParseException(exMessage, root); } return new CheckStylePluginException(exMessage, root); }  CheckStylePluginException wrap(@Nullable final String message, @NotNull final Throwable error);  }### Answer:
@Test public void anExceptionThatIsNotACheckstyleExceptionIsWrappedInAPluginException() { assertThat( new ExceptionWrapper().wrap(null, new NullPointerException("aTestException")), is(instanceOf(CheckStylePluginException.class))); }
@Test public void aCheckstyleExceptionThatHasACauseOfARecognitionExceptionIsWrappedInAPluginParseException() { assertThat( new ExceptionWrapper() .wrap(null, new CheckstyleException("aTestException", new RecognitionException("aTestException"))), is(instanceOf(CheckStylePluginParseException.class))); }
@Test public void aCheckstyleExceptionThatHasACauseOfASubclassOfRecognitionExceptionIsWrappedInAPluginParseException() { assertThat( new ExceptionWrapper() .wrap(null, new CheckstyleException("aTestException", new MismatchedTokenException())), is(instanceOf(CheckStylePluginParseException.class))); }
@Test public void aCheckstyleExceptionThatHasACauseOfATokenStreamExceptionIsWrappedInAPluginParseException() { assertThat( new ExceptionWrapper() .wrap(null, new CheckstyleException("aTestException", new TokenStreamException("aTestException"))), is(instanceOf(CheckStylePluginParseException.class))); }
@Test public void aCheckstyleExceptionThatHasACauseOfANullPointerExceptionIsWrappedInAPluginParseException() { assertThat( new ExceptionWrapper() .wrap(null, new CheckstyleException("aTestException", new NullPointerException("aTestException"))), is(instanceOf(CheckStylePluginParseException.class))); }
@Test public void aCheckstyleExceptionThatHasACauseOfAnArrayIndexOutOfBoundsExceptionIsWrappedInAPluginParseException() { assertThat( new ExceptionWrapper() .wrap(null, new CheckstyleException("aTestException", new ArrayIndexOutOfBoundsException("aTestException"))), is(instanceOf(CheckStylePluginParseException.class))); }
@Test public void aCheckstyleExceptionThatHasACauseOfAnIllegalStateExceptionIsWrappedInAPluginParseException() { assertThat( new ExceptionWrapper() .wrap(null, new CheckstyleException("aTestException", new IllegalStateException("aTestException"))), is(instanceOf(CheckStylePluginParseException.class))); }
@Test public void aCheckstyleExceptionThatHasACauseOfAStringIndexOutOfBoundsExceptionIsWrappedInAPluginParseException() { assertThat( new ExceptionWrapper() .wrap(null, new CheckstyleException("aTestException", new StringIndexOutOfBoundsException("aTestException"))), is(instanceOf(CheckStylePluginParseException.class))); }
@Test public void aCheckstyleExceptionThatHasACauseOfAClassCastExceptionIsWrappedInAPluginParseException() { assertThat( new ExceptionWrapper() .wrap(null, new CheckstyleException("aTestException", new ClassCastException("aTestException"))), is(instanceOf(CheckStylePluginParseException.class))); }
@Test public void aCheckstyleExceptionThatHasACauseOfAnyOtherExceptionIsWrappedInAPluginException() { assertThat( new ExceptionWrapper() .wrap(null, new CheckstyleException("aTestException", new IllegalStateException("aTestException"))), is(instanceOf(CheckStylePluginException.class))); }