From 3ebe8ac8ca578aa1226689e80c817f7b12e53b67 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Sun, 17 Nov 2024 00:02:48 +0100 Subject: [PATCH] Added method ConfigRuntimeException.convertToRuntimeEx() --- .../java/core/cfg/ConfigRuntimeException.java | 34 ++++++++++++++++++- .../core/cfg/TestConfigRuntimeException.java | 11 ++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/fj-core/src/main/java/org/fugerit/java/core/cfg/ConfigRuntimeException.java b/fj-core/src/main/java/org/fugerit/java/core/cfg/ConfigRuntimeException.java index f84f31ad..ce44f99c 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/cfg/ConfigRuntimeException.java +++ b/fj-core/src/main/java/org/fugerit/java/core/cfg/ConfigRuntimeException.java @@ -69,5 +69,37 @@ public static ConfigRuntimeException convertExMethod( String method, Exception e public static ConfigRuntimeException convertEx( Exception e ) { return convertEx( ExConverUtils.DEFAULT_CAUSE_MESSAGE, e ); } - + + /** + * Convert the exception to ConfigRuntimeException + * + * RuntimeException are left unchanged + * + * @param baseMessage the base message + * @param e the exception + * @return the runtime exception + */ + public static RuntimeException convertToRuntimeEx( String baseMessage, Exception e ) { + RuntimeException res = null; + if ( e instanceof RuntimeException ) { + res = (RuntimeException)e; + } else { + res = new ConfigRuntimeException( ExConverUtils.defaultMessage(baseMessage, e), e ); + } + return res; + } + + + /** + * Convert the exception to ConfigRuntimeException + * + * RuntimeException are left unchanged + * + * @param e the exception + * @return the runtime exception + */ + public static RuntimeException convertToRuntimeEx( Exception e ) { + return convertToRuntimeEx( ExConverUtils.DEFAULT_CAUSE_MESSAGE, e ); + } + } diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfigRuntimeException.java b/fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfigRuntimeException.java index 3cc85353..95680d07 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfigRuntimeException.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfigRuntimeException.java @@ -45,6 +45,17 @@ public void testEx6() { public void testEx7() { Assert.assertNotNull( ConfigRuntimeException.convertExMethod( "e" , new SQLException( "f" ) ) ); } + + @Test + public void testEx21() { + Assert.assertNotNull( ConfigRuntimeException.convertToRuntimeEx( new ConfigRuntimeException( "y" ) ) ); + } + + + @Test + public void testEx22() { + Assert.assertNotNull( ConfigRuntimeException.convertToRuntimeEx( new IOException( "z" ) ) ); + } @Test public void testEx8() {