Skip to content

Commit

Permalink
More tests for suppressed exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ash2k committed Sep 22, 2013
1 parent 183bd2c commit 409cbb7
Showing 1 changed file with 58 additions and 0 deletions.
Expand Up @@ -17,6 +17,7 @@
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;

Expand All @@ -31,7 +32,9 @@
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.classic.util.TeztHelper;

import static ch.qos.logback.classic.util.TeztHelper.addSuppressed;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;

public class ThrowableProxyConverterTest {

Expand All @@ -56,6 +59,57 @@ private ILoggingEvent createLoggingEvent(Throwable t) {
null);
}

@Test
public void suppressed() throws InvocationTargetException, IllegalAccessException
{
assumeTrue(TeztHelper.suppressedSupported()); // only execute on Java 7, would work anyway but doesn't make sense.
Exception ex = null;
try {
someMethod();
} catch (Exception e) {
Exception fooException = new Exception("Foo");
Exception barException = new Exception("Bar");
addSuppressed(e, fooException);
addSuppressed(e, barException);
ex = e;
}
verify(ex);
}

@Test
public void suppressedWithCause() throws InvocationTargetException, IllegalAccessException
{
assumeTrue(TeztHelper.suppressedSupported()); // only execute on Java 7, would work anyway but doesn't make sense.
Exception ex = null;
try {
someMethod();
} catch (Exception e) {
ex=new Exception("Wrapper", e);
Exception fooException = new Exception("Foo");
Exception barException = new Exception("Bar");
addSuppressed(ex, fooException);
addSuppressed(e, barException);
}
verify(ex);
}

@Test
public void suppressedWithSuppressed() throws Exception
{
assumeTrue(TeztHelper.suppressedSupported()); // only execute on Java 7, would work anyway but doesn't make sense.
Exception ex = null;
try {
someMethod();
} catch (Exception e) {
ex=new Exception("Wrapper", e);
Exception fooException = new Exception("Foo");
Exception barException = new Exception("Bar");
addSuppressed(barException, fooException);
addSuppressed(e, barException);
}
verify(ex);
}

@Test
public void smoke() {
Exception t = new Exception("smoke");
Expand Down Expand Up @@ -104,6 +158,10 @@ public void withShortArgument() throws Exception {
assertNull("Unexpected line in stack trace", reader.readLine());
}

void someMethod() throws Exception {
throw new Exception("someMethod");
}

void verify(Throwable t) {
t.printStackTrace(pw);

Expand Down

0 comments on commit 409cbb7

Please sign in to comment.