From 28bcdf4b92a1db275c4f898d9ba4936a3c1a52f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Suszy=C5=84ski?= Date: Wed, 7 Oct 2015 21:32:05 +0200 Subject: [PATCH] Adding eid runtime ex test for coverage --- .../exceptions/EidRuntimeExceptionTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/test/java/pl/wavesoftware/eid/exceptions/EidRuntimeExceptionTest.java diff --git a/src/test/java/pl/wavesoftware/eid/exceptions/EidRuntimeExceptionTest.java b/src/test/java/pl/wavesoftware/eid/exceptions/EidRuntimeExceptionTest.java new file mode 100644 index 0000000..5cb6f0d --- /dev/null +++ b/src/test/java/pl/wavesoftware/eid/exceptions/EidRuntimeExceptionTest.java @@ -0,0 +1,43 @@ +package pl.wavesoftware.eid.exceptions; + +import org.hamcrest.CoreMatchers; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import javax.xml.bind.JAXBException; +import java.util.UnknownFormatConversionException; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage; + +/** + * @author Krzysztof SuszyƄski + * @since 2015-10-07 + */ +@SuppressWarnings("ConstantConditions") +public class EidRuntimeExceptionTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testGetMessage() { + // then + thrown.expect(EidRuntimeException.class); + thrown.expectCause(CoreMatchers.instanceOf(JAXBException.class)); + thrown.expectCause(hasMessage(is((String) null))); + thrown.expectMessage(containsString("20151007:212217")); + thrown.expectMessage(containsString("javax.xml.bind.JAXBException\n - with linked exception:\n" + + "[java.util.UnknownFormatConversionException: Conversion = 'Invalid for unit test']")); + + // given + String message = null; + Throwable original = new UnknownFormatConversionException("Invalid for unit test"); + JAXBException cause = new JAXBException(message); + cause.setLinkedException(original); + throw new EidRuntimeException("20151007:212217", cause); + } + +} \ No newline at end of file