From ffda9da7eaaddc9c4ddbe3b293ddfdc0c806a837 Mon Sep 17 00:00:00 2001 From: bbilger Date: Thu, 22 Jun 2017 00:57:18 +0200 Subject: [PATCH] fix sonar complaints; #20 --- .../ConditionalBase64ReadInterceptor.java | 3 +-- .../com/jrestless/test/DynamicJerseyTestRunner.java | 12 ++---------- .../src/main/java/com/jrestless/test/IOUtils.java | 9 ++++++++- .../test/UtilityClassCodeCoverageBumper.java | 10 +++++++++- .../jrestless/test/DynamicJerseyTestRunnerTest.java | 6 +++--- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/core/jrestless-core-container/src/main/java/com/jrestless/core/interceptor/ConditionalBase64ReadInterceptor.java b/core/jrestless-core-container/src/main/java/com/jrestless/core/interceptor/ConditionalBase64ReadInterceptor.java index 8c709d0..b36428b 100644 --- a/core/jrestless-core-container/src/main/java/com/jrestless/core/interceptor/ConditionalBase64ReadInterceptor.java +++ b/core/jrestless-core-container/src/main/java/com/jrestless/core/interceptor/ConditionalBase64ReadInterceptor.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.util.Base64; -import javax.ws.rs.WebApplicationException; import javax.ws.rs.ext.ReaderInterceptor; import javax.ws.rs.ext.ReaderInterceptorContext; @@ -33,7 +32,7 @@ public abstract class ConditionalBase64ReadInterceptor implements ReaderInterceptor { @Override - public final Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException { + public final Object aroundReadFrom(ReaderInterceptorContext context) throws IOException { if (isBase64(context)) { context.setInputStream(Base64.getDecoder().wrap(context.getInputStream())); } diff --git a/test/jrestless-test/src/main/java/com/jrestless/test/DynamicJerseyTestRunner.java b/test/jrestless-test/src/main/java/com/jrestless/test/DynamicJerseyTestRunner.java index 88af7d3..9618dda 100644 --- a/test/jrestless-test/src/main/java/com/jrestless/test/DynamicJerseyTestRunner.java +++ b/test/jrestless-test/src/main/java/com/jrestless/test/DynamicJerseyTestRunner.java @@ -41,18 +41,10 @@ public class DynamicJerseyTestRunner { */ public void runJerseyTest(JerseyTest jerseyTest, ThrowingConsumer test) throws Exception { try { - try { - jerseyTest.setUp(); - } catch (Exception e) { - throw new RuntimeException(e); - } + jerseyTest.setUp(); test.accept(jerseyTest); } finally { - try { - jerseyTest.tearDown(); - } catch (Exception e) { - throw new RuntimeException(e); - } + jerseyTest.tearDown(); } } diff --git a/test/jrestless-test/src/main/java/com/jrestless/test/IOUtils.java b/test/jrestless-test/src/main/java/com/jrestless/test/IOUtils.java index 0849b45..116fafa 100644 --- a/test/jrestless-test/src/main/java/com/jrestless/test/IOUtils.java +++ b/test/jrestless-test/src/main/java/com/jrestless/test/IOUtils.java @@ -54,7 +54,7 @@ public static byte[] toBytes(InputStream is) { buffer.flush(); return buffer.toByteArray(); } catch (IOException ioe) { - throw new RuntimeException(ioe); + throw new IORuntimeException(ioe); } } @@ -85,4 +85,11 @@ public static String toString(InputStream is, Charset charset) { return new String(toBytes(is), charset); } + public static final class IORuntimeException extends RuntimeException { + private static final long serialVersionUID = 1L; + private IORuntimeException(IOException ioe) { + super(ioe); + } + } + } diff --git a/test/jrestless-test/src/main/java/com/jrestless/test/UtilityClassCodeCoverageBumper.java b/test/jrestless-test/src/main/java/com/jrestless/test/UtilityClassCodeCoverageBumper.java index 07e5e9d..8b89c7e 100644 --- a/test/jrestless-test/src/main/java/com/jrestless/test/UtilityClassCodeCoverageBumper.java +++ b/test/jrestless-test/src/main/java/com/jrestless/test/UtilityClassCodeCoverageBumper.java @@ -21,7 +21,15 @@ public static void invokePrivateConstructor(Class clazz) { constructor.newInstance(); } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - throw new RuntimeException(e); + throw new ConstructorInvocationException(e); } } + + public static final class ConstructorInvocationException extends RuntimeException { + private static final long serialVersionUID = 1L; + private ConstructorInvocationException(Exception e) { + super(e); + } + + } } diff --git a/test/jrestless-test/src/test/java/com/jrestless/test/DynamicJerseyTestRunnerTest.java b/test/jrestless-test/src/test/java/com/jrestless/test/DynamicJerseyTestRunnerTest.java index 11ba15e..088a449 100644 --- a/test/jrestless-test/src/test/java/com/jrestless/test/DynamicJerseyTestRunnerTest.java +++ b/test/jrestless-test/src/test/java/com/jrestless/test/DynamicJerseyTestRunnerTest.java @@ -41,7 +41,7 @@ public void testRethrowsExceptionOnStartupFailure() throws Exception { runner.runJerseyTest(jerseyTest, consumer); fail("expected exception to be thrown"); } catch (RuntimeException re) { - assertSame(thrownException, re.getCause()); + assertSame(thrownException, re); } } @@ -64,7 +64,7 @@ public void testRethrowsExceptionOnTearDownFailure() throws Exception { runner.runJerseyTest(jerseyTest, consumer); fail("expected exception to be thrown"); } catch (RuntimeException re) { - assertSame(thrownException, re.getCause()); + assertSame(thrownException, re); } } @@ -117,7 +117,7 @@ public void testRethrowsTearDownExceptionOnConsumerAndTearDownFailure() throws E runner.runJerseyTest(jerseyTest, consumer); fail("expected exception to be thrown"); } catch (Exception e) { - assertSame(tearDownException, e.getCause()); + assertSame(tearDownException, e); } } }