From e9fd35a303a5f5f41726c3216c8acd7598a3a494 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 7 Feb 2018 17:13:32 -0500 Subject: Add ExtractAppender to facilite junit tests Added ExtractAppender to provide a way for junit tests to capture data sent to a logger. Changed logback.version to 1.2.3 and moved the property to the top-level pom. Updated license date in top-level pom. Refactored ExceptionsText, adding ErrorsTester and ThrowablesTester classes to reduce sonar issues. Change-Id: Ief7d08972bf4e7037b59c2afe4b77b252f2ad60a Issue-ID: POLICY-582 Signed-off-by: Jim Hahn --- .../common/utils/test/ExceptionsTesterTest.java | 110 ++------------------- 1 file changed, 6 insertions(+), 104 deletions(-) (limited to 'utils-test/src/test/java/org/onap/policy/common/utils/test/ExceptionsTesterTest.java') diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/test/ExceptionsTesterTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/test/ExceptionsTesterTest.java index c6af77a2..3848acd0 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/test/ExceptionsTesterTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/test/ExceptionsTesterTest.java @@ -27,124 +27,26 @@ import org.junit.Test; public class ExceptionsTesterTest { @Test - public void test() throws Exception { + public void test() { assertEquals(2, new ExceptionsTester().test(SimpleException.class)); assertEquals(8, new ExceptionsTester().test(StaticException.class)); } @Test(expected = AssertionError.class) - public void testIgnoreMessageException() throws Exception { - new ExceptionsTester().test(IgnoreMessageException.class); - } - - @Test(expected = AssertionError.class) - public void testIgnoreCauseException() throws Exception { - new ExceptionsTester().test(IgnoreCauseException.class); - } - - @Test(expected = AssertionError.class) - public void testNonStaticException() throws Exception { + public void testNoConstructorsException() { new ExceptionsTester().test(NoConstructorsException.class); } - @Test(expected = AssertionError.class) - public void testAlwaysSuppressException() throws Exception { - new ExceptionsTester().test(AlwaysSuppressException.class); - } - - @Test(expected = AssertionError.class) - public void testNeverSuppressException() throws Exception { - new ExceptionsTester().test(NeverSuppressException.class); - } - - @Test(expected = AssertionError.class) - public void testAlwaysWritableException() throws Exception { - new ExceptionsTester().test(AlwaysWritableException.class); - } - - @Test(expected = AssertionError.class) - public void testNeverWritableException() throws Exception { - new ExceptionsTester().test(NeverWritableException.class); - } - /** - * Used to test a failure case - message text is ignored. - */ - public static class IgnoreMessageException extends Exception { - private static final long serialVersionUID = 1L; - - public IgnoreMessageException(String message) { - super("bogus"); - } - } - - /** - * Used to test a failure case - cause is ignored. - */ - public static class IgnoreCauseException extends Exception { - private static final long serialVersionUID = 1L; - - public IgnoreCauseException(Throwable cause) { - super(new Exception("another cause")); - } - } - - /** - * Used to test a failure case - this has no standard constructions. + * Used to test a failure case - this has no standard constructors. The only + * constructor it has takes an "int", thus it is not one of the standard + * constructors. */ public static class NoConstructorsException extends Exception { private static final long serialVersionUID = 1L; public NoConstructorsException(int value) { - super(String.valueOf(value)); - } - } - - /** - * Used to test a failure case - always suppresses. - */ - public static class AlwaysSuppressException extends Exception { - private static final long serialVersionUID = 1L; - - public AlwaysSuppressException(String message, Throwable cause, boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, true, writableStackTrace); - } - } - - /** - * Used to test a failure case - never suppresses. - */ - public static class NeverSuppressException extends Exception { - private static final long serialVersionUID = 1L; - - public NeverSuppressException(String message, Throwable cause, boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, false, writableStackTrace); - } - } - - /** - * Used to test a failure case - always allows stack writes. - */ - public static class AlwaysWritableException extends Exception { - private static final long serialVersionUID = 1L; - - public AlwaysWritableException(String message, Throwable cause, boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, enableSuppression, true); - } - } - - /** - * Used to test a failure case - never allows stack writes. - */ - public static class NeverWritableException extends Exception { - private static final long serialVersionUID = 1L; - - public NeverWritableException(String message, Throwable cause, boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, enableSuppression, false); + super(); } } -- cgit 1.2.3-korg