From da4474221b49d65f07f87eae506e6220b30f6db3 Mon Sep 17 00:00:00 2001 From: Niklas Baudy Date: Sat, 19 Mar 2016 13:28:02 +0100 Subject: [PATCH] Deprecate CompositeException constructor with message prefix --- .../java/rx/exceptions/CompositeException.java | 2 ++ src/main/java/rx/exceptions/Exceptions.java | 3 +-- .../rx/exceptions/CompositeExceptionTest.java | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/rx/exceptions/CompositeException.java b/src/main/java/rx/exceptions/CompositeException.java index 58930c061a..be6169060c 100644 --- a/src/main/java/rx/exceptions/CompositeException.java +++ b/src/main/java/rx/exceptions/CompositeException.java @@ -41,6 +41,8 @@ public final class CompositeException extends RuntimeException { private final List exceptions; private final String message; + /** @deprecated please use {@link #CompositeException(Collection)} */ + @Deprecated public CompositeException(String messagePrefix, Collection errors) { Set deDupedExceptions = new LinkedHashSet(); List _exceptions = new ArrayList(); diff --git a/src/main/java/rx/exceptions/Exceptions.java b/src/main/java/rx/exceptions/Exceptions.java index 2b94504c08..6c37167c3e 100644 --- a/src/main/java/rx/exceptions/Exceptions.java +++ b/src/main/java/rx/exceptions/Exceptions.java @@ -171,8 +171,7 @@ public static void throwIfAny(List exceptions) { throw new RuntimeException(t); } } - throw new CompositeException( - "Multiple exceptions", exceptions); + throw new CompositeException(exceptions); } } diff --git a/src/test/java/rx/exceptions/CompositeExceptionTest.java b/src/test/java/rx/exceptions/CompositeExceptionTest.java index ec3bd7b6c5..a08ce23382 100644 --- a/src/test/java/rx/exceptions/CompositeExceptionTest.java +++ b/src/test/java/rx/exceptions/CompositeExceptionTest.java @@ -23,6 +23,7 @@ import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.junit.Test; @@ -50,7 +51,7 @@ public void testMultipleWithSameCause() { Throwable e1 = new Throwable("1", rootCause); Throwable e2 = new Throwable("2", rootCause); Throwable e3 = new Throwable("3", rootCause); - CompositeException ce = new CompositeException("3 failures with same root cause", Arrays.asList(e1, e2, e3)); + CompositeException ce = new CompositeException(Arrays.asList(e1, e2, e3)); System.err.println("----------------------------- print composite stacktrace"); ce.printStackTrace(); @@ -174,7 +175,7 @@ public void testNullCollection() { } @Test public void testNullElement() { - CompositeException composite = new CompositeException(Arrays.asList((Throwable)null)); + CompositeException composite = new CompositeException(Collections.singletonList((Throwable) null)); composite.getCause(); composite.printStackTrace(); } @@ -220,4 +221,16 @@ public synchronized Throwable initCause(Throwable cause) { System.err.println("----------------------------- print cause stacktrace"); cex.getCause().printStackTrace(); } + + @Test + public void messageCollection() { + CompositeException compositeException = new CompositeException(Arrays.asList(ex1, ex3)); + assertEquals("2 exceptions occurred. ", compositeException.getMessage()); + } + + @Test + public void messageVarargs() { + CompositeException compositeException = new CompositeException(ex1, ex2, ex3); + assertEquals("3 exceptions occurred. ", compositeException.getMessage()); + } } \ No newline at end of file