This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 3b749080c26 CAMEL-21196: modernized assertions in camel-core.language 
(#15724)
3b749080c26 is described below

commit 3b749080c2674080644be99447a891d01cd99a2e
Author: LostArtist <[email protected]>
AuthorDate: Thu Sep 26 16:35:33 2024 +0200

    CAMEL-21196: modernized assertions in camel-core.language (#15724)
---
 .../language/BeanLanguageInvalidOGNLTest.java      |  25 +-
 .../BeanLanguageMethodMissingParenthesisTest.java  |  32 +-
 .../java/org/apache/camel/language/BeanTest.java   |  33 +-
 .../apache/camel/language/FileLanguageTest.java    |  65 +--
 .../apache/camel/language/NoSuchLanguageTest.java  |  15 +-
 .../java/org/apache/camel/language/RefTest.java    |  24 +-
 .../language/XPathLanguageSingleNodeListTest.java  |  15 +-
 .../camel/language/simple/SimpleOperatorTest.java  | 138 +++---
 .../simple/SimpleParserExpressionInvalidTest.java  |  59 +--
 .../simple/SimpleParserPredicateInvalidTest.java   |  79 ++-
 .../apache/camel/language/simple/SimpleTest.java   | 549 ++++++++++-----------
 11 files changed, 477 insertions(+), 557 deletions(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/BeanLanguageInvalidOGNLTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/language/BeanLanguageInvalidOGNLTest.java
index 3620c194c0d..fa7d314091b 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/language/BeanLanguageInvalidOGNLTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/BeanLanguageInvalidOGNLTest.java
@@ -27,7 +27,7 @@ import 
org.apache.camel.component.bean.MethodNotFoundException;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class BeanLanguageInvalidOGNLTest extends ContextTestSupport {
 
@@ -39,18 +39,17 @@ public class BeanLanguageInvalidOGNLTest extends 
ContextTestSupport {
                 
from("direct:start").transform().method(MyReallyCoolBean.class, "getOther[xx");
             }
         });
-        try {
-            context.start();
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            RuntimeCamelException rce = 
assertIsInstanceOf(RuntimeCamelException.class, e);
-            MethodNotFoundException mnfe = 
assertIsInstanceOf(MethodNotFoundException.class, rce.getCause());
-            assertEquals("getOther[xx", mnfe.getMethodName());
-            ExpressionIllegalSyntaxException cause
-                    = 
assertIsInstanceOf(ExpressionIllegalSyntaxException.class, mnfe.getCause());
-            assertEquals("Illegal syntax: getOther[xx", cause.getMessage());
-            assertEquals("getOther[xx", cause.getExpression());
-        }
+
+        Exception e = assertThrows(Exception.class, () -> context.start(),
+                "Should have thrown exception");
+
+        RuntimeCamelException rce = 
assertIsInstanceOf(RuntimeCamelException.class, e);
+        MethodNotFoundException mnfe = 
assertIsInstanceOf(MethodNotFoundException.class, rce.getCause());
+        assertEquals("getOther[xx", mnfe.getMethodName());
+        ExpressionIllegalSyntaxException cause
+                = assertIsInstanceOf(ExpressionIllegalSyntaxException.class, 
mnfe.getCause());
+        assertEquals("Illegal syntax: getOther[xx", cause.getMessage());
+        assertEquals("getOther[xx", cause.getExpression());
     }
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/BeanLanguageMethodMissingParenthesisTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/language/BeanLanguageMethodMissingParenthesisTest.java
index 8e0e2825eea..ee3ed2fc5d5 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/language/BeanLanguageMethodMissingParenthesisTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/BeanLanguageMethodMissingParenthesisTest.java
@@ -22,7 +22,7 @@ import org.apache.camel.builder.RouteBuilder;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class BeanLanguageMethodMissingParenthesisTest extends 
ContextTestSupport {
 
@@ -70,13 +70,12 @@ public class BeanLanguageMethodMissingParenthesisTest 
extends ContextTestSupport
         });
         context.start();
 
-        try {
-            template.sendBodyAndHeader("direct:start", "Hello World", "foo", 
"yes");
-            fail("Should throw exception");
-        } catch (CamelExecutionException e) {
-            IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
-            assertEquals("Method should end with parenthesis, was 
couldThisBeFoo(${body}, ${header.foo}", iae.getMessage());
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.sendBodyAndHeader("direct:start", "Hello 
World", "foo", "yes"),
+                "Should throw exception");
+
+        IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
+        assertEquals("Method should end with parenthesis, was 
couldThisBeFoo(${body}, ${header.foo}", iae.getMessage());
     }
 
     @Test
@@ -93,15 +92,14 @@ public class BeanLanguageMethodMissingParenthesisTest 
extends ContextTestSupport
         });
         context.start();
 
-        try {
-            template.sendBodyAndHeader("direct:start", "Hello World", "foo", 
"yes");
-            fail("Should throw exception");
-        } catch (CamelExecutionException e) {
-            IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
-            assertEquals(
-                    "Method name must start with a valid java identifier at 
position: 0 in method: --couldThisBeFoo(${body}, ${header.foo})",
-                    iae.getMessage());
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.sendBodyAndHeader("direct:start", "Hello 
World", "foo", "yes"),
+                "Should throw exception");
+
+        IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
+        assertEquals(
+                "Method name must start with a valid java identifier at 
position: 0 in method: --couldThisBeFoo(${body}, ${header.foo})",
+                iae.getMessage());
     }
 
     public boolean couldThisBeFoo(String body, String header) {
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/BeanTest.java 
b/core/camel-core/src/test/java/org/apache/camel/language/BeanTest.java
index 71360aeb258..89ba7429ee5 100644
--- a/core/camel-core/src/test/java/org/apache/camel/language/BeanTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/language/BeanTest.java
@@ -54,12 +54,11 @@ public class BeanTest extends LanguageTestSupport {
     @Test
     public void testDoubleColon() {
         assertPredicate("foo::isFooHeaderAbc");
-        try {
-            assertPredicateFails("foo:isFooHeaderAbc");
-            fail("Should throw exception");
-        } catch (NoSuchBeanException e) {
-            assertEquals("foo:isFooHeaderAbc", e.getName());
-        }
+        NoSuchBeanException e = assertThrows(NoSuchBeanException.class,
+                () -> assertPredicateFails("foo:isFooHeaderAbc"),
+                "Should throw exception");
+
+        assertEquals("foo:isFooHeaderAbc", e.getName());
     }
 
     @Test
@@ -96,26 +95,24 @@ public class BeanTest extends LanguageTestSupport {
     @Test
     public void testNoMethod() {
         MyUser user = new MyUser();
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             Expression exp = new BeanExpression(user, "unknown");
             exp.init(context);
-            fail("Should throw exception");
-        } catch (Exception e) {
-            MethodNotFoundException mnfe = 
assertIsInstanceOf(MethodNotFoundException.class, e);
-            assertSame(user, mnfe.getBean());
-            assertEquals("unknown", mnfe.getMethodName());
-        }
+        }, "Should throw exception");
+
+        MethodNotFoundException mnfe = 
assertIsInstanceOf(MethodNotFoundException.class, e);
+        assertSame(user, mnfe.getBean());
+        assertEquals("unknown", mnfe.getMethodName());
     }
 
     @Test
     public void testNoMethodBeanLookup() {
-        try {
+        MethodNotFoundException e = 
assertThrows(MethodNotFoundException.class, () -> {
             Expression exp = new BeanExpression("foo", "cake");
             exp.init(context);
-            fail("Should throw exception");
-        } catch (MethodNotFoundException e) {
-            assertEquals("cake", e.getMethodName());
-        }
+        }, "Should throw exception");
+
+        assertEquals("cake", e.getMethodName());
     }
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java 
b/core/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
index 4b48d0c1145..21fa6942536 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
@@ -32,8 +32,8 @@ import org.apache.camel.util.FileUtil;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 /**
  * Unit test for File Language.
@@ -68,12 +68,11 @@ public class FileLanguageTest extends LanguageTestSupport {
     @Test
     public void testInvalidSyntax() {
         assertExpression("${file:onlyname}", file.getName());
-        try {
-            assertExpression("${file:onlyName}", file.getName());
-            fail("Should have thrown exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage().startsWith("Unknown file language 
syntax: onlyName at location 0"));
-        }
+        ExpressionIllegalSyntaxException e = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("${file:onlyName}", file.getName()),
+                "Should have thrown exception");
+
+        assertTrue(e.getMessage().startsWith("Unknown file language syntax: 
onlyName at location 0"));
     }
 
     @Test
@@ -130,12 +129,9 @@ public class FileLanguageTest extends LanguageTestSupport {
         assertExpression("backup-${date:header.birthday:yyyyMMdd}", 
"backup-19740420");
         assertExpression("hello-${date:header.special:yyyyMMdd}", 
"hello-20080808");
 
-        try {
-            this.assertExpression("nodate-${date:header.xxx:yyyyMMdd}", null);
-            fail("Should have thrown IllegalArgumentException");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
+        assertThrows(IllegalArgumentException.class,
+                () -> 
this.assertExpression("nodate-${date:header.xxx:yyyyMMdd}", null),
+                "Should have thrown IllegalArgumentException");
     }
 
     @Test
@@ -149,12 +145,9 @@ public class FileLanguageTest extends LanguageTestSupport {
         assertExpression("backup-$simple{date:header.birthday:yyyyMMdd}", 
"backup-19740420");
         assertExpression("hello-$simple{date:header.special:yyyyMMdd}", 
"hello-20080808");
 
-        try {
-            this.assertExpression("nodate-$simple{date:header.xxx:yyyyMMdd}", 
null);
-            fail("Should have thrown IllegalArgumentException");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
+        assertThrows(IllegalArgumentException.class,
+                () -> 
this.assertExpression("nodate-$simple{date:header.xxx:yyyyMMdd}", null),
+                "Should have thrown IllegalArgumentException");
     }
 
     @Test
@@ -226,27 +219,23 @@ public class FileLanguageTest extends LanguageTestSupport 
{
 
     @Test
     public void testIllegalSyntax() {
-        try {
-            // it should be with colon
-            assertExpression("${file.name}", "");
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage().startsWith("Unknown function: file.name 
at location 0"));
-        }
+        ExpressionIllegalSyntaxException e1 = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("${file.name}", ""),
+                "Should have thrown an exception");
 
-        try {
-            assertExpression("hey ${xxx} how are you?", "");
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage().startsWith("Unknown function: xxx at 
location 4"));
-        }
+        assertTrue(e1.getMessage().startsWith("Unknown function: file.name at 
location 0"));
 
-        try {
-            assertExpression("${xxx}", "");
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage().startsWith("Unknown function: xxx at 
location 0"));
-        }
+        ExpressionIllegalSyntaxException e2 = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("hey ${xxx} how are you?", ""),
+                "Should have thrown an exception");
+
+        assertTrue(e2.getMessage().startsWith("Unknown function: xxx at 
location 4"));
+
+        ExpressionIllegalSyntaxException e3 = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("${xxx}", ""),
+                "Should have thrown an exception");
+
+        assertTrue(e3.getMessage().startsWith("Unknown function: xxx at 
location 0"));
     }
 
     @Test
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/NoSuchLanguageTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/language/NoSuchLanguageTest.java
index c81e1ad1505..5a72795c62c 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/language/NoSuchLanguageTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/NoSuchLanguageTest.java
@@ -21,19 +21,18 @@ import org.apache.camel.NoSuchLanguageException;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class NoSuchLanguageTest extends LanguageTestSupport {
 
     @Test
     public void testNoSuchLanguage() {
-        try {
-            assertPredicate("foo");
-            fail("Should have thrown an exception");
-        } catch (NoSuchLanguageException e) {
-            assertEquals("No language could be found for: unknown", 
e.getMessage());
-            assertEquals("unknown", e.getLanguage());
-        }
+        NoSuchLanguageException e = assertThrows(NoSuchLanguageException.class,
+                () -> assertPredicate("foo"),
+                "Should have thrown an exception");
+
+        assertEquals("No language could be found for: unknown", 
e.getMessage());
+        assertEquals("unknown", e.getLanguage());
     }
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/RefTest.java 
b/core/camel-core/src/test/java/org/apache/camel/language/RefTest.java
index e46f4ed7a25..b9a7cb154d7 100644
--- a/core/camel-core/src/test/java/org/apache/camel/language/RefTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/language/RefTest.java
@@ -23,7 +23,7 @@ import org.apache.camel.support.ExpressionAdapter;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class RefTest extends LanguageTestSupport {
 
@@ -41,12 +41,11 @@ public class RefTest extends LanguageTestSupport {
 
     @Test
     public void testRefExpressionsNotFound() {
-        try {
-            assertExpression("foo", "Hello World");
-            fail("Should have thrown exception");
-        } catch (IllegalArgumentException e) {
-            assertEquals("Cannot find expression or predicate in registry with 
ref: foo", e.getMessage());
-        }
+        IllegalArgumentException e = 
assertThrows(IllegalArgumentException.class,
+                () -> assertExpression("foo", "Hello World"),
+                "Should have thrown an exception");
+
+        assertEquals("Cannot find expression or predicate in registry with 
ref: foo", e.getMessage());
     }
 
     @Test
@@ -58,12 +57,11 @@ public class RefTest extends LanguageTestSupport {
     @Test
     public void testRefDynamicExpressionsNotFound() {
         exchange.getMessage().setHeader("foo", "myExp2");
-        try {
-            assertExpression("${header.foo}", "Hello World");
-            fail("Should have thrown exception");
-        } catch (IllegalArgumentException e) {
-            assertEquals("Cannot find expression or predicate in registry with 
ref: myExp2", e.getMessage());
-        }
+        IllegalArgumentException e = 
assertThrows(IllegalArgumentException.class,
+                () -> assertExpression("${header.foo}", "Hello World"),
+                "Should have thrown an exception");
+
+        assertEquals("Cannot find expression or predicate in registry with 
ref: myExp2", e.getMessage());
     }
 
     @Test
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/XPathLanguageSingleNodeListTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/language/XPathLanguageSingleNodeListTest.java
index 260175caec8..2fb76580489 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/language/XPathLanguageSingleNodeListTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/XPathLanguageSingleNodeListTest.java
@@ -24,7 +24,7 @@ import org.apache.camel.builder.RouteBuilder;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 /**
  * Tests new converters added to XmlConverters to make Camel intelligent when 
needing to convert a NodeList of length 1
@@ -66,13 +66,12 @@ public class XPathLanguageSingleNodeListTest extends 
ContextTestSupport {
         getMockEndpoint("mock:notfound").expectedMessageCount(0);
         getMockEndpoint("mock:notfound").setResultWaitTime(500);
 
-        try {
-            template.requestBody("direct:doTest", XML_INPUT_MULTIPLE, 
String.class);
-            fail("NoTypeConversionAvailableException expected");
-        } catch (CamelExecutionException ex) {
-            assertEquals(RuntimeCamelException.class, 
ex.getCause().getClass());
-            assertEquals(NoTypeConversionAvailableException.class, 
ex.getCause().getCause().getClass());
-        }
+        CamelExecutionException ex = 
assertThrows(CamelExecutionException.class,
+                () -> template.requestBody("direct:doTest", 
XML_INPUT_MULTIPLE, String.class),
+                "NoTypeConversionAvailableException expected");
+
+        assertEquals(RuntimeCamelException.class, ex.getCause().getClass());
+        assertEquals(NoTypeConversionAvailableException.class, 
ex.getCause().getCause().getClass());
 
         assertMockEndpointsSatisfied();
     }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
index 74c491c1185..b0973f552e8 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
@@ -23,7 +23,7 @@ import org.apache.camel.spi.Registry;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SimpleOperatorTest extends LanguageTestSupport {
 
@@ -606,12 +606,11 @@ public class SimpleOperatorTest extends 
LanguageTestSupport {
         assertPredicate("${in.header.foo} is 'String'", true);
         assertPredicate("${in.header.foo} is 'Integer'", false);
 
-        try {
-            assertPredicate("${in.header.foo} is com.mycompany.DoesNotExist", 
false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(20, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${in.header.foo} is 
com.mycompany.DoesNotExist", false),
+                "Should have thrown an exception");
+
+        assertEquals(20, e.getIndex());
     }
 
     @Test
@@ -626,18 +625,17 @@ public class SimpleOperatorTest extends 
LanguageTestSupport {
         assertPredicate("${in.header.foo} !is 'String'", false);
         assertPredicate("${in.header.foo} !is 'Integer'", true);
 
-        try {
-            assertPredicate("${in.header.foo} not is 
com.mycompany.DoesNotExist", false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(24, e.getIndex());
-        }
-        try {
-            assertPredicate("${in.header.foo} !is com.mycompany.DoesNotExist", 
false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(21, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e1 = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${in.header.foo} not is 
com.mycompany.DoesNotExist", false),
+                "Should have thrown an exception");
+
+        assertEquals(24, e1.getIndex());
+
+        SimpleIllegalSyntaxException e2 = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${in.header.foo} !is 
com.mycompany.DoesNotExist", false),
+                "Should have thrown an exception");
+
+        assertEquals(21, e2.getIndex());
     }
 
     @Test
@@ -651,26 +649,23 @@ public class SimpleOperatorTest extends 
LanguageTestSupport {
         assertPredicate("${bean:generator.generateId} range '120..122'", 
false);
         assertPredicate("${bean:generator.generateId} range '124..130'", 
false);
 
-        try {
-            assertPredicate("${in.header.foo} range abc..200", false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(23, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e1 = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${in.header.foo} range abc..200", 
false),
+                "Should have thrown an exception");
 
-        try {
-            assertPredicate("${in.header.foo} range abc..", false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(23, e.getIndex());
-        }
+        assertEquals(23, e1.getIndex());
 
-        try {
-            assertPredicate("${in.header.foo} range 100.200", false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(30, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e2 = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${in.header.foo} range abc..", false),
+                "Should have thrown an exception");
+
+        assertEquals(23, e2.getIndex());
+
+        SimpleIllegalSyntaxException e3 = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${in.header.foo} range 100.200", false),
+                "Should have thrown an exception");
+
+        assertEquals(30, e3.getIndex());
 
         assertPredicate("${in.header.bar} range '100..200' && ${in.header.foo} 
== 'abc'", true);
         assertPredicate("${in.header.bar} range '200..300' && ${in.header.foo} 
== 'abc'", false);
@@ -696,44 +691,41 @@ public class SimpleOperatorTest extends 
LanguageTestSupport {
         assertPredicate("${bean:generator.generateId} !range '120..122'", 
true);
         assertPredicate("${bean:generator.generateId} !range '124..130'", 
true);
 
-        try {
-            assertPredicate("${in.header.foo} not range abc..200", false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(27, e.getIndex());
-        }
-        try {
-            assertPredicate("${in.header.foo} !range abc..200", false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(24, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e1 = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${in.header.foo} not range abc..200", 
false),
+                "Should have thrown an exception");
 
-        try {
-            assertPredicate("${in.header.foo} not range abc..", false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(27, e.getIndex());
-        }
-        try {
-            assertPredicate("${in.header.foo} !range abc..", false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(24, e.getIndex());
-        }
+        assertEquals(27, e1.getIndex());
 
-        try {
-            assertPredicate("${in.header.foo} not range 100.200", false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(34, e.getIndex());
-        }
-        try {
-            assertPredicate("${in.header.foo} !range 100.200", false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(31, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e2 = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${in.header.foo} !range abc..200", 
false),
+                "Should have thrown an exception");
+
+        assertEquals(24, e2.getIndex());
+
+        SimpleIllegalSyntaxException e3 = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${in.header.foo} not range abc..", 
false),
+                "Should have thrown an exception");
+
+        assertEquals(27, e3.getIndex());
+
+        SimpleIllegalSyntaxException e4 = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${in.header.foo} !range abc..", false),
+                "Should have thrown an exception");
+
+        assertEquals(24, e4.getIndex());
+
+        SimpleIllegalSyntaxException e5 = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${in.header.foo} not range 100.200", 
false),
+                "Should have thrown an exception");
+
+        assertEquals(34, e5.getIndex());
+
+        SimpleIllegalSyntaxException e6 = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${in.header.foo} !range 100.200", 
false),
+                "Should have thrown an exception");
+
+        assertEquals(31, e6.getIndex());
     }
 
     @Test
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserExpressionInvalidTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserExpressionInvalidTest.java
index b7cfbbcbcba..f573fccb68a 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserExpressionInvalidTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserExpressionInvalidTest.java
@@ -21,7 +21,7 @@ import 
org.apache.camel.language.simple.types.SimpleIllegalSyntaxException;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 /**
  *
@@ -31,59 +31,50 @@ public class SimpleParserExpressionInvalidTest extends 
ExchangeTestSupport {
     @Test
     public void testSimpleUnbalanceFunction() {
         SimpleExpressionParser parser = new SimpleExpressionParser(context, 
"${body is a nice day", true, null);
-        try {
-            parser.parseExpression();
-            fail("Should thrown exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(19, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                parser::parseExpression, "Should thrown exception");
+
+        assertEquals(19, e.getIndex());
     }
 
     @Test
     public void testSimpleNestedUnbalanceFunction() {
         SimpleExpressionParser parser = new SimpleExpressionParser(context, 
"${body${foo}", true, null);
-        try {
-            parser.parseExpression();
-            fail("Should thrown exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(11, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                parser::parseExpression, "Should thrown exception");
+
+        assertEquals(11, e.getIndex());
     }
 
     @Test
     public void testSimpleUnknownFunction() {
         SimpleExpressionParser parser = new SimpleExpressionParser(context, 
"Hello ${foo} how are you?", true, null);
-        try {
-            parser.parseExpression();
-            fail("Should thrown exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(6, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                parser::parseExpression, "Should thrown exception");
+
+        assertEquals(6, e.getIndex());
     }
 
     @Test
     public void testSimpleNestedUnknownFunction() {
         SimpleExpressionParser parser = new SimpleExpressionParser(context, 
"Hello ${bodyAs(${foo})} how are you?", true, null);
-        try {
-            // nested functions can only be syntax evaluated when evaluating an
-            // exchange at runtime
-            parser.parseExpression().evaluate(exchange, String.class);
-            fail("Should thrown exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            // its a nested function is it reset the index
-            assertEquals(0, e.getIndex());
-        }
+        // nested functions can only be syntax evaluated when evaluating an
+        // exchange at runtime
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> parser.parseExpression().evaluate(exchange, 
String.class),
+                "Should thrown exception");
+
+        assertEquals(0, e.getIndex());
     }
 
     @Test
     public void testNoEndFunction() {
         SimpleExpressionParser parser = new SimpleExpressionParser(context, 
"Hello ${body", true, null);
-        try {
-            parser.parseExpression();
-            fail("Should thrown exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(11, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                parser::parseExpression,
+                "Should thrown exception");
+
+        assertEquals(11, e.getIndex());
     }
 
 }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java
index 416161f876d..62ae2699e7f 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java
@@ -21,7 +21,7 @@ import 
org.apache.camel.language.simple.types.SimpleIllegalSyntaxException;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 /**
  *
@@ -34,12 +34,11 @@ public class SimpleParserPredicateInvalidTest extends 
ExchangeTestSupport {
         exchange.getIn().setHeader("high", true);
 
         SimplePredicateParser parser = new SimplePredicateParser(context, 
"${header.high} == abc", true, null);
-        try {
-            parser.parsePredicate();
-            fail("Should thrown exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(19, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                parser::parsePredicate,
+                "Should thrown exception");
+
+        assertEquals(19, e.getIndex());
     }
 
     @Test
@@ -48,12 +47,11 @@ public class SimpleParserPredicateInvalidTest extends 
ExchangeTestSupport {
         exchange.getIn().setHeader("high", true);
 
         SimplePredicateParser parser = new SimplePredicateParser(context, 
"${header.high} = true", true, null);
-        try {
-            parser.parsePredicate();
-            fail("Should thrown exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(15, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                parser::parsePredicate,
+                "Should thrown exception");
+
+        assertEquals(15, e.getIndex());
     }
 
     @Test
@@ -61,12 +59,11 @@ public class SimpleParserPredicateInvalidTest extends 
ExchangeTestSupport {
         exchange.getIn().setBody("foo");
 
         SimplePredicateParser parser = new SimplePredicateParser(context, 
"${body} == 'foo", true, null);
-        try {
-            parser.parsePredicate();
-            fail("Should thrown exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(14, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                parser::parsePredicate,
+                "Should thrown exception");
+
+        assertEquals(14, e.getIndex());
     }
 
     @Test
@@ -74,12 +71,11 @@ public class SimpleParserPredicateInvalidTest extends 
ExchangeTestSupport {
         exchange.getIn().setBody("foo");
 
         SimplePredicateParser parser = new SimplePredicateParser(context, 
"${body} == \"foo", true, null);
-        try {
-            parser.parsePredicate();
-            fail("Should thrown exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(14, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                parser::parsePredicate,
+                "Should thrown exception");
+
+        assertEquals(14, e.getIndex());
     }
 
     @Test
@@ -88,12 +84,11 @@ public class SimpleParserPredicateInvalidTest extends 
ExchangeTestSupport {
 
         SimplePredicateParser parser
                 = new SimplePredicateParser(context, "${body} == 'foo' && && 
${header} == 123", true, null);
-        try {
-            parser.parsePredicate();
-            fail("Should thrown exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(20, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                parser::parsePredicate,
+                "Should thrown exception");
+
+        assertEquals(20, e.getIndex());
     }
 
     @Test
@@ -102,12 +97,11 @@ public class SimpleParserPredicateInvalidTest extends 
ExchangeTestSupport {
 
         SimplePredicateParser parser
                 = new SimplePredicateParser(context, "${body} == 'foo' || || 
${header} == 123", true, null);
-        try {
-            parser.parsePredicate();
-            fail("Should thrown exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(20, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                parser::parsePredicate,
+                "Should thrown exception");
+
+        assertEquals(20, e.getIndex());
     }
 
     @Test
@@ -115,12 +109,11 @@ public class SimpleParserPredicateInvalidTest extends 
ExchangeTestSupport {
         exchange.getIn().setBody("foo");
 
         SimplePredicateParser parser = new SimplePredicateParser(context, 
"${body} == == 'foo'", true, null);
-        try {
-            parser.parsePredicate();
-            fail("Should thrown exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(13, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                parser::parsePredicate,
+                "Should thrown exception");
+
+        assertEquals(13, e.getIndex());
     }
 
 }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
index 346ae8c83e7..ae9bdc6147d 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
@@ -63,7 +63,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 public class SimpleTest extends LanguageTestSupport {
 
@@ -141,21 +140,21 @@ public class SimpleTest extends LanguageTestSupport {
     public void testEmptyExpression() {
         assertExpression("", "");
         assertExpression(" ", " ");
-        try {
-            assertExpression(null, null);
-            fail("Should have thrown exception");
-        } catch (IllegalArgumentException e) {
-            assertEquals("expression must be specified", e.getMessage());
-        }
+
+        IllegalArgumentException e1 = 
assertThrows(IllegalArgumentException.class,
+                () -> assertExpression(null, null),
+                "Should have thrown exception");
+
+        assertEquals("expression must be specified", e1.getMessage());
 
         assertPredicate("", false);
         assertPredicate(" ", false);
-        try {
-            assertPredicate(null, false);
-            fail("Should have thrown exception");
-        } catch (IllegalArgumentException e) {
-            assertEquals("expression must be specified", e.getMessage());
-        }
+
+        IllegalArgumentException e2 = 
assertThrows(IllegalArgumentException.class,
+                () -> assertPredicate(null, false),
+                "Should have thrown exception");
+
+        assertEquals("expression must be specified", e2.getMessage());
     }
 
     @Test
@@ -202,12 +201,9 @@ public class SimpleTest extends LanguageTestSupport {
         assertNotNull(exp);
 
         // must start with a dot
-        try {
-            context.resolveLanguage("simple").createExpression("${bodyxxx}");
-            fail("Should throw exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            // expected
-        }
+        assertThrows(SimpleIllegalSyntaxException.class,
+                () -> 
context.resolveLanguage("simple").createExpression("${bodyxxx}"),
+                "Should throw exception");
     }
 
     @Test
@@ -387,13 +383,12 @@ public class SimpleTest extends LanguageTestSupport {
 
         // there is no upper case method on byte array, but we can convert to
         // String as below
-        try {
-            assertPredicate("${body.toUpperCase()} == 'HELLO WORLD'", true);
-            fail("Should throw exception");
-        } catch (RuntimeBeanExpressionException e) {
-            MethodNotFoundException cause = 
assertIsInstanceOf(MethodNotFoundException.class, e.getCause());
-            assertEquals("toUpperCase()", cause.getMethodName());
-        }
+        RuntimeBeanExpressionException e = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertPredicate("${body.toUpperCase()} == 'HELLO 
WORLD'", true),
+                "Should throw exception");
+
+        MethodNotFoundException cause = 
assertIsInstanceOf(MethodNotFoundException.class, e.getCause());
+        assertEquals("toUpperCase()", cause.getMethodName());
 
         assertPredicate("${bodyAs(String)} == 'hello world'", true);
         assertPredicate("${bodyAs(String).toUpperCase()} == 'HELLO WORLD'", 
true);
@@ -409,13 +404,12 @@ public class SimpleTest extends LanguageTestSupport {
 
         // there is no upper case method on byte array, but we can convert to
         // String as below
-        try {
-            assertPredicate("${body.toUpperCase()} == 'HELLO WORLD'", true);
-            fail("Should throw exception");
-        } catch (RuntimeBeanExpressionException e) {
-            MethodNotFoundException cause = 
assertIsInstanceOf(MethodNotFoundException.class, e.getCause());
-            assertEquals("toUpperCase()", cause.getMethodName());
-        }
+        RuntimeBeanExpressionException e = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertPredicate("${body.toUpperCase()} == 'HELLO 
WORLD'", true),
+                "Should throw exception");
+
+        MethodNotFoundException cause = 
assertIsInstanceOf(MethodNotFoundException.class, e.getCause());
+        assertEquals("toUpperCase()", cause.getMethodName());
 
         assertPredicate("${mandatoryBodyAs(String)} == 'hello world'", true);
         assertPredicate("${mandatoryBodyAs(String).toUpperCase()} == 'HELLO 
WORLD'", true);
@@ -464,13 +458,14 @@ public class SimpleTest extends LanguageTestSupport {
 
         assertExpression("${exchangeProperty.wicket[0]}", "Camel in Action");
         assertExpression("${exchangeProperty.wicket[1]}", "ActiveMQ in 
Action");
-        try {
-            assertExpression("${exchangeProperty.wicket[2]}", "");
-            fail("Should have thrown an exception");
-        } catch (Exception e) {
-            IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
-            assertEquals(INDEX_OUT_OF_BOUNDS_ERROR_MSG, cause.getMessage());
-        }
+
+        Exception e = assertThrows(Exception.class,
+                () -> assertExpression("${exchangeProperty.wicket[2]}", ""),
+                "Should have thrown an exception");
+
+        IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
+        assertEquals(INDEX_OUT_OF_BOUNDS_ERROR_MSG, cause.getMessage());
+
         assertExpression("${exchangeProperty.unknown[cool]}", null);
     }
 
@@ -483,13 +478,14 @@ public class SimpleTest extends LanguageTestSupport {
 
         assertExpression("${exchangeProperty.wicket[0].getId}", 123);
         assertExpression("${exchangeProperty.wicket[1].getName}", "ActiveMQ in 
Action");
-        try {
-            assertExpression("${exchangeProperty.wicket[2]}", "");
-            fail("Should have thrown an exception");
-        } catch (Exception e) {
-            IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
-            assertEquals(INDEX_OUT_OF_BOUNDS_ERROR_MSG, cause.getMessage());
-        }
+
+        Exception e = assertThrows(Exception.class,
+                () -> assertExpression("${exchangeProperty.wicket[2]}", ""),
+                "Should have thrown an exception");
+
+        IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
+        assertEquals(INDEX_OUT_OF_BOUNDS_ERROR_MSG, cause.getMessage());
+
         assertExpression("${exchangeProperty.unknown[cool]}", null);
     }
 
@@ -538,36 +534,33 @@ public class SimpleTest extends LanguageTestSupport {
 
     @Test
     public void testOGNLPropertyMapNotMap() {
-        try {
-            assertExpression("${exchangeProperty.foobar[bar]}", null);
-            fail("Should have thrown an exception");
-        } catch (RuntimeBeanExpressionException e) {
-            IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
-            assertEquals("Key: bar not found in bean: cba of type: 
java.lang.String using OGNL path [[bar]]",
-                    cause.getMessage());
-        }
+        RuntimeBeanExpressionException e = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertExpression("${exchangeProperty.foobar[bar]}", 
null),
+                "Should have thrown an exception");
+
+        IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
+        assertEquals("Key: bar not found in bean: cba of type: 
java.lang.String using OGNL path [[bar]]",
+                cause.getMessage());
     }
 
     @Test
     public void testOGNLPropertyMapIllegalSyntax() {
-        try {
-            assertExpression("${exchangeProperty.foobar[bar}", null);
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage()
-                    .startsWith("Valid syntax: ${exchangeProperty.OGNL} was: 
exchangeProperty.foobar[bar at location 0"));
-        }
+        ExpressionIllegalSyntaxException e = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("${exchangeProperty.foobar[bar}", null),
+                "Should have thrown an exception");
+
+        assertTrue(e.getMessage()
+                .startsWith("Valid syntax: ${exchangeProperty.OGNL} was: 
exchangeProperty.foobar[bar at location 0"));
     }
 
     @Test
     public void testOGNLExchangePropertyMapIllegalSyntax() {
-        try {
-            assertExpression("${exchangeProperty.foobar[bar}", null);
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage()
-                    .startsWith("Valid syntax: ${exchangeProperty.OGNL} was: 
exchangeProperty.foobar[bar at location 0"));
-        }
+        ExpressionIllegalSyntaxException e = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("${exchangeProperty.foobar[bar}", null),
+                "Should have thrown an exception");
+
+        assertTrue(e.getMessage()
+                .startsWith("Valid syntax: ${exchangeProperty.OGNL} was: 
exchangeProperty.foobar[bar at location 0"));
     }
 
     @Test
@@ -613,12 +606,11 @@ public class SimpleTest extends LanguageTestSupport {
         assertExpression("${date:exchangeProperty.birthday:yyyyMMdd}", 
"19760622");
         assertExpression("${date:exchangeProperty.birthday+24h:yyyyMMdd}", 
"19760623");
 
-        try {
-            assertExpression("${date:yyyyMMdd}", "19740420");
-            fail("Should thrown an exception");
-        } catch (IllegalArgumentException e) {
-            assertEquals("Command not supported for dateExpression: yyyyMMdd", 
e.getMessage());
-        }
+        IllegalArgumentException e = 
assertThrows(IllegalArgumentException.class,
+                () -> assertExpression("${date:yyyyMMdd}", "19740420"),
+                "Should thrown an exception");
+
+        assertEquals("Command not supported for dateExpression: yyyyMMdd", 
e.getMessage());
     }
 
     @Test
@@ -641,12 +633,11 @@ public class SimpleTest extends LanguageTestSupport {
         assertExpression("${date:header.birthday:yyyyMMdd}", "19740420");
         assertExpression("${date:exchangeProperty.birthday:yyyyMMdd}", 
"19740420");
 
-        try {
-            assertExpression("${date:header.other:yyyyMMdd}", "19740420");
-            fail("Should thrown an exception");
-        } catch (IllegalArgumentException e) {
-            assertEquals("Cannot find Date/long object at command: 
header.other", e.getMessage());
-        }
+        IllegalArgumentException e = 
assertThrows(IllegalArgumentException.class,
+                () -> assertExpression("${date:header.other:yyyyMMdd}", 
"19740420"),
+                "Should thrown an exception");
+
+        assertEquals("Cannot find Date/long object at command: header.other", 
e.getMessage());
     }
 
     @Test
@@ -728,12 +719,11 @@ public class SimpleTest extends LanguageTestSupport {
 
     @Test
     public void testInvalidComplexExpression() {
-        try {
-            assertExpression("hey ${foo", "bad expression!");
-            fail("Should have thrown an exception!");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(8, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertExpression("hey ${foo", "bad expression!"),
+                "Should have thrown an exception!");
+
+        assertEquals(8, e.getIndex());
     }
 
     @Test
@@ -799,12 +789,11 @@ public class SimpleTest extends LanguageTestSupport {
         assertExpression("${bodyAs(int)}", 456);
         assertExpression("${bodyAs('int')}", 456);
 
-        try {
-            assertExpression("${bodyAs(XXX)}", 456);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(ClassNotFoundException.class, e.getCause());
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> assertExpression("${bodyAs(XXX)}", 456),
+                "Should have thrown an exception");
+
+        assertIsInstanceOf(ClassNotFoundException.class, e.getCause());
     }
 
     @Test
@@ -813,24 +802,22 @@ public class SimpleTest extends LanguageTestSupport {
         assertExpression("${mandatoryBodyAs('String')}", "<hello 
id='m123'>world!</hello>");
 
         exchange.getIn().setBody(null);
-        try {
-            assertExpression("${mandatoryBodyAs('String')}", "");
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(InvalidPayloadException.class, e.getCause());
-        }
+        CamelExecutionException e1 = 
assertThrows(CamelExecutionException.class,
+                () -> assertExpression("${mandatoryBodyAs('String')}", ""),
+                "Should have thrown exception");
+
+        assertIsInstanceOf(InvalidPayloadException.class, e1.getCause());
 
         exchange.getIn().setBody(456);
         assertExpression("${mandatoryBodyAs(Integer)}", 456);
         assertExpression("${mandatoryBodyAs(int)}", 456);
         assertExpression("${mandatoryBodyAs('int')}", 456);
 
-        try {
-            assertExpression("${mandatoryBodyAs(XXX)}", 456);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(ClassNotFoundException.class, e.getCause());
-        }
+        CamelExecutionException e2 = 
assertThrows(CamelExecutionException.class,
+                () -> assertExpression("${mandatoryBodyAs(XXX)}", 456),
+                "Should have thrown an exception");
+
+        assertIsInstanceOf(ClassNotFoundException.class, e2.getCause());
     }
 
     @Test
@@ -888,12 +875,11 @@ public class SimpleTest extends LanguageTestSupport {
         // set an empty body
         exchange.getIn().setBody(null);
 
-        try {
-            assertPredicate("${body} is null", false);
-            fail("Should have thrown an exception");
-        } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(11, e.getIndex());
-        }
+        SimpleIllegalSyntaxException e = 
assertThrows(SimpleIllegalSyntaxException.class,
+                () -> assertPredicate("${body} is null", false),
+                "Should have thrown an exception");
+
+        assertEquals(11, e.getIndex());
     }
 
     @Test
@@ -938,26 +924,23 @@ public class SimpleTest extends LanguageTestSupport {
 
         assertExpression("${headerAs(unknown,String)}", null);
 
-        try {
-            assertExpression("${headerAs(unknown String)}", null);
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage().startsWith("Valid syntax: 
${headerAs(key, type)} was: headerAs(unknown String)"));
-        }
+        ExpressionIllegalSyntaxException e1 = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("${headerAs(unknown String)}", null),
+                "Should have thrown an exception");
 
-        try {
-            assertExpression("${headerAs(fool,String).test}", null);
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage().startsWith("Valid syntax: 
${headerAs(key, type)} was: headerAs(fool,String).test"));
-        }
+        assertTrue(e1.getMessage().startsWith("Valid syntax: ${headerAs(key, 
type)} was: headerAs(unknown String)"));
 
-        try {
-            assertExpression("${headerAs(bar,XXX)}", 123);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(ClassNotFoundException.class, e.getCause());
-        }
+        ExpressionIllegalSyntaxException e2 = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("${headerAs(fool,String).test}", null),
+                "Should have thrown an exception");
+
+        assertTrue(e2.getMessage().startsWith("Valid syntax: ${headerAs(key, 
type)} was: headerAs(fool,String).test"));
+
+        CamelExecutionException e3 = 
assertThrows(CamelExecutionException.class,
+                () -> assertExpression("${headerAs(bar,XXX)}", 123),
+                "Should have thrown an exception");
+
+        assertIsInstanceOf(ClassNotFoundException.class, e3.getCause());
     }
 
     @Test
@@ -1045,50 +1028,44 @@ public class SimpleTest extends LanguageTestSupport {
 
         assertExpression("${variableAs(unknown,String)}", null);
 
-        try {
-            assertExpression("${variableAs(unknown String)}", null);
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage().startsWith("Valid syntax: 
${variableAs(key, type)} was: variableAs(unknown String)"));
-        }
+        ExpressionIllegalSyntaxException e1 = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("${variableAs(unknown String)}", null),
+                "Should have thrown an exception");
 
-        try {
-            assertExpression("${variableAs(fool,String).test}", null);
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage().startsWith("Valid syntax: 
${variableAs(key, type)} was: variableAs(fool,String).test"));
-        }
+        assertTrue(e1.getMessage().startsWith("Valid syntax: ${variableAs(key, 
type)} was: variableAs(unknown String)"));
 
-        try {
-            assertExpression("${variableAs(bar,XXX)}", 123);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(ClassNotFoundException.class, e.getCause());
-        }
+        ExpressionIllegalSyntaxException e2 = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("${variableAs(fool,String).test}", 
null),
+                "Should have thrown an exception");
+
+        assertTrue(e2.getMessage().startsWith("Valid syntax: ${variableAs(key, 
type)} was: variableAs(fool,String).test"));
+
+        CamelExecutionException e3 = 
assertThrows(CamelExecutionException.class,
+                () -> assertExpression("${variableAs(bar,XXX)}", 123),
+                "Should have thrown an exception");
+
+        assertIsInstanceOf(ClassNotFoundException.class, e3.getCause());
     }
 
     @Test
     public void testIllegalSyntax() {
-        try {
-            assertExpression("hey ${xxx} how are you?", "");
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage().startsWith("Unknown function: xxx at 
location 4"));
-        }
+        ExpressionIllegalSyntaxException e1 = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("hey ${xxx} how are you?", ""),
+                "Should have thrown an exception");
 
-        try {
-            assertExpression("${xxx}", "");
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage().startsWith("Unknown function: xxx at 
location 0"));
-        }
+        assertTrue(e1.getMessage().startsWith("Unknown function: xxx at 
location 4"));
 
-        try {
-            assertExpression("${bodyAs(xxx}", "");
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage().startsWith("Valid syntax: 
${bodyAs(type)} was: bodyAs(xxx"));
-        }
+        ExpressionIllegalSyntaxException e2 = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("${xxx}", ""),
+                "Should have thrown an exception");
+
+        assertTrue(e2.getMessage().startsWith("Unknown function: xxx at 
location 0"));
+
+        ExpressionIllegalSyntaxException e3 = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("${bodyAs(xxx}", ""),
+                "Should have thrown an exception");
+
+        assertTrue(e3.getMessage().startsWith("Valid syntax: ${bodyAs(type)} 
was: bodyAs(xxx"));
     }
 
     @Test
@@ -1100,13 +1077,13 @@ public class SimpleTest extends LanguageTestSupport {
 
         assertExpression("${header.wicket[0]}", "Camel in Action");
         assertExpression("${header.wicket[1]}", "ActiveMQ in Action");
-        try {
-            assertExpression("${header.wicket[2]}", "");
-            fail("Should have thrown an exception");
-        } catch (Exception e) {
-            IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
-            assertEquals(INDEX_OUT_OF_BOUNDS_ERROR_MSG, cause.getMessage());
-        }
+        Exception e = assertThrows(Exception.class,
+                () -> assertExpression("${header.wicket[2]}", ""),
+                "Should have thrown an exception");
+
+        IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
+        assertEquals(INDEX_OUT_OF_BOUNDS_ERROR_MSG, cause.getMessage());
+
         assertExpression("${header.unknown[cool]}", null);
     }
 
@@ -1119,13 +1096,13 @@ public class SimpleTest extends LanguageTestSupport {
 
         assertExpression("${header.wicket[0].getId}", 123);
         assertExpression("${header.wicket[1].getName}", "ActiveMQ in Action");
-        try {
-            assertExpression("${header.wicket[2]}", "");
-            fail("Should have thrown an exception");
-        } catch (Exception e) {
-            IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
-            assertEquals(INDEX_OUT_OF_BOUNDS_ERROR_MSG, cause.getMessage());
-        }
+        Exception e = assertThrows(Exception.class,
+                () -> assertExpression("${header.wicket[2]}", ""),
+                "Should have thrown an exception");
+
+        IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
+        assertEquals(INDEX_OUT_OF_BOUNDS_ERROR_MSG, cause.getMessage());
+
         assertExpression("${header.unknown[cool]}", null);
     }
 
@@ -1157,24 +1134,22 @@ public class SimpleTest extends LanguageTestSupport {
 
     @Test
     public void testOGNLHeaderMapNotMap() {
-        try {
-            assertExpression("${header.foo[bar]}", null);
-            fail("Should have thrown an exception");
-        } catch (RuntimeBeanExpressionException e) {
-            IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
-            assertEquals("Key: bar not found in bean: abc of type: 
java.lang.String using OGNL path [[bar]]",
-                    cause.getMessage());
-        }
+        RuntimeBeanExpressionException e = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertExpression("${header.foo[bar]}", null),
+                "Should have thrown an exception");
+
+        IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
+        assertEquals("Key: bar not found in bean: abc of type: 
java.lang.String using OGNL path [[bar]]",
+                cause.getMessage());
     }
 
     @Test
     public void testOGNLHeaderMapIllegalSyntax() {
-        try {
-            assertExpression("${header.foo[bar}", null);
-            fail("Should have thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            assertTrue(e.getMessage().startsWith("Valid syntax: 
${header.name[key]} was: header.foo[bar"));
-        }
+        ExpressionIllegalSyntaxException e = 
assertThrows(ExpressionIllegalSyntaxException.class,
+                () -> assertExpression("${header.foo[bar}", null),
+                "Should have thrown an exception");
+
+        assertTrue(e.getMessage().startsWith("Valid syntax: 
${header.name[key]} was: header.foo[bar"));
     }
 
     @Test
@@ -1440,29 +1415,26 @@ public class SimpleTest extends LanguageTestSupport {
 
         exchange.getIn().setBody(order);
 
-        try {
-            assertExpression("${in.body.getLines[3].getId}", 123);
-            fail("Should have thrown an exception");
-        } catch (RuntimeBeanExpressionException e) {
-            IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
-            assertTrue(cause.getMessage().startsWith("Index: 3, Size: 2 out of 
bounds with List from bean"));
-        }
+        RuntimeBeanExpressionException e1 = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertExpression("${in.body.getLines[3].getId}", 123),
+                "Should have thrown an exception");
 
-        try {
-            assertExpression("${in.body.getLines[last-2].getId}", 123);
-            fail("Should have thrown an exception");
-        } catch (RuntimeBeanExpressionException e) {
-            IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
-            assertTrue(cause.getMessage().startsWith("Index: -1, Size: 2 out 
of bounds with List from bean"));
-        }
+        IndexOutOfBoundsException cause1 = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e1.getCause());
+        assertTrue(cause1.getMessage().startsWith("Index: 3, Size: 2 out of 
bounds with List from bean"));
 
-        try {
-            assertExpression("${in.body.getLines[last - XXX].getId}", 123);
-            fail("Should have thrown an exception");
-        } catch (RuntimeBeanExpressionException e) {
-            ExpressionIllegalSyntaxException cause = 
assertIsInstanceOf(ExpressionIllegalSyntaxException.class, e.getCause());
-            assertEquals("last - XXX", cause.getExpression());
-        }
+        RuntimeBeanExpressionException e2 = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertExpression("${in.body.getLines[last-2].getId}", 
123),
+                "Should have thrown an exception");
+
+        IndexOutOfBoundsException cause2 = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e2.getCause());
+        assertTrue(cause2.getMessage().startsWith("Index: -1, Size: 2 out of 
bounds with List from bean"));
+
+        RuntimeBeanExpressionException e3 = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertExpression("${in.body.getLines[last - 
XXX].getId}", 123),
+                "Should have thrown an exception");
+
+        ExpressionIllegalSyntaxException cause3 = 
assertIsInstanceOf(ExpressionIllegalSyntaxException.class, e3.getCause());
+        assertEquals("last - XXX", cause3.getExpression());
     }
 
     @Test
@@ -1474,29 +1446,26 @@ public class SimpleTest extends LanguageTestSupport {
 
         exchange.getIn().setBody(order);
 
-        try {
-            assertExpression("${in.body.lines[3].id}", 123);
-            fail("Should have thrown an exception");
-        } catch (RuntimeBeanExpressionException e) {
-            IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
-            assertTrue(cause.getMessage().startsWith("Index: 3, Size: 2 out of 
bounds with List from bean"));
-        }
+        RuntimeBeanExpressionException e1 = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertExpression("${in.body.lines[3].id}", 123),
+                "Should have thrown an exception");
 
-        try {
-            assertExpression("${in.body.lines[last - 2].id}", 123);
-            fail("Should have thrown an exception");
-        } catch (RuntimeBeanExpressionException e) {
-            IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
-            assertTrue(cause.getMessage().startsWith("Index: -1, Size: 2 out 
of bounds with List from bean"));
-        }
+        IndexOutOfBoundsException cause1 = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e1.getCause());
+        assertTrue(cause1.getMessage().startsWith("Index: 3, Size: 2 out of 
bounds with List from bean"));
 
-        try {
-            assertExpression("${in.body.lines[last - XXX].id}", 123);
-            fail("Should have thrown an exception");
-        } catch (RuntimeBeanExpressionException e) {
-            ExpressionIllegalSyntaxException cause = 
assertIsInstanceOf(ExpressionIllegalSyntaxException.class, e.getCause());
-            assertEquals("last - XXX", cause.getExpression());
-        }
+        RuntimeBeanExpressionException e2 = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertExpression("${in.body.lines[last - 2].id}", 123),
+                "Should have thrown an exception");
+
+        IndexOutOfBoundsException cause2 = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e2.getCause());
+        assertTrue(cause2.getMessage().startsWith("Index: -1, Size: 2 out of 
bounds with List from bean"));
+
+        RuntimeBeanExpressionException e3 = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertExpression("${in.body.lines[last - XXX].id}", 123),
+                "Should have thrown an exception");
+
+        ExpressionIllegalSyntaxException cause3 = 
assertIsInstanceOf(ExpressionIllegalSyntaxException.class, e3.getCause());
+        assertEquals("last - XXX", cause3.getExpression());
     }
 
     @Test
@@ -1532,13 +1501,12 @@ public class SimpleTest extends LanguageTestSupport {
 
         exchange.getIn().setBody(order);
 
-        try {
-            assertExpression("${in.body.getLines[0]?.getRating}", "");
-            fail("Should have thrown exception");
-        } catch (RuntimeBeanExpressionException e) {
-            MethodNotFoundException cause = 
assertIsInstanceOf(MethodNotFoundException.class, e.getCause());
-            assertEquals("getRating", cause.getMethodName());
-        }
+        RuntimeBeanExpressionException e = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertExpression("${in.body.getLines[0]?.getRating}", 
""),
+                "Should have thrown exception");
+
+        MethodNotFoundException cause = 
assertIsInstanceOf(MethodNotFoundException.class, e.getCause());
+        assertEquals("getRating", cause.getMethodName());
     }
 
     @Test
@@ -1550,13 +1518,12 @@ public class SimpleTest extends LanguageTestSupport {
 
         exchange.getIn().setBody(order);
 
-        try {
-            assertExpression("${in.body.lines[0]?.rating}", "");
-            fail("Should have thrown exception");
-        } catch (RuntimeBeanExpressionException e) {
-            MethodNotFoundException cause = 
assertIsInstanceOf(MethodNotFoundException.class, e.getCause());
-            assertEquals("rating", cause.getMethodName());
-        }
+        RuntimeBeanExpressionException e = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertExpression("${in.body.lines[0]?.rating}", ""),
+                "Should have thrown exception");
+
+        MethodNotFoundException cause = 
assertIsInstanceOf(MethodNotFoundException.class, e.getCause());
+        assertEquals("rating", cause.getMethodName());
     }
 
     @Test
@@ -1575,16 +1542,16 @@ public class SimpleTest extends LanguageTestSupport {
 
         // using null safe to avoid the NPE
         assertExpression("${in.body.getFriend?.getFriend.getName}", null);
-        try {
-            // without null safe we get an NPE
-            assertExpression("${in.body.getFriend.getFriend.getName}", "");
-            fail("Should have thrown exception");
-        } catch (RuntimeBeanExpressionException e) {
-            assertEquals(
-                    "Failed to invoke method: .getFriend.getFriend.getName on 
org.apache.camel.language.simple.SimpleTest.Animal"
-                         + " due last method returned null and therefore 
cannot continue to invoke method .getName on a null instance",
-                    e.getMessage());
-        }
+
+        // without null safe we get an NPE
+        RuntimeBeanExpressionException e = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> 
assertExpression("${in.body.getFriend.getFriend.getName}", ""),
+                "Should have thrown exception");
+
+        assertEquals(
+                "Failed to invoke method: .getFriend.getFriend.getName on 
org.apache.camel.language.simple.SimpleTest.Animal"
+                     + " due last method returned null and therefore cannot 
continue to invoke method .getName on a null instance",
+                e.getMessage());
     }
 
     @Test
@@ -1604,15 +1571,15 @@ public class SimpleTest extends LanguageTestSupport {
 
         // using null safe to avoid the NPE
         assertExpression("${in.body.friend?.friend.name}", null);
-        try {
-            // without null safe we get an NPE
-            assertExpression("${in.body.friend.friend.name}", "");
-            fail("Should have thrown exception");
-        } catch (RuntimeBeanExpressionException e) {
-            assertEquals("Failed to invoke method: .friend.friend.name on 
org.apache.camel.language.simple.SimpleTest.Animal"
-                         + " due last method returned null and therefore 
cannot continue to invoke method .name on a null instance",
-                    e.getMessage());
-        }
+
+        // without null safe we get an NPE
+        RuntimeBeanExpressionException e = 
assertThrows(RuntimeBeanExpressionException.class,
+                () -> assertExpression("${in.body.friend.friend.name}", ""),
+                "Should have thrown exception");
+
+        assertEquals("Failed to invoke method: .friend.friend.name on 
org.apache.camel.language.simple.SimpleTest.Animal"
+                     + " due last method returned null and therefore cannot 
continue to invoke method .name on a null instance",
+                e.getMessage());
     }
 
     @Test
@@ -1849,18 +1816,17 @@ public class SimpleTest extends LanguageTestSupport {
         assertExpression("${type:org.apache.camel.ExchangePattern.InOut}", 
ExchangePattern.InOut);
 
         // non existing fields
-        try {
-            assertExpression("${type:org.apache.camel.ExchangePattern.}", 
null);
-            fail("Should throw exception");
-        } catch (Exception e) {
-            assertIsInstanceOf(ClassNotFoundException.class, e.getCause());
-        }
-        try {
-            
assertExpression("${type:org.apache.camel.ExchangePattern.UNKNOWN}", null);
-            fail("Should throw exception");
-        } catch (Exception e) {
-            assertIsInstanceOf(ClassNotFoundException.class, e.getCause());
-        }
+        Exception e1 = assertThrows(Exception.class,
+                () -> 
assertExpression("${type:org.apache.camel.ExchangePattern.}", null),
+                "Should throw exception");
+
+        assertIsInstanceOf(ClassNotFoundException.class, e1.getCause());
+
+        Exception e2 = assertThrows(Exception.class,
+                () -> 
assertExpression("${type:org.apache.camel.ExchangePattern.UNKNOWN}", null),
+                "Should throw exception");
+
+        assertIsInstanceOf(ClassNotFoundException.class, e2.getCause());
     }
 
     @Test
@@ -2043,18 +2009,17 @@ public class SimpleTest extends LanguageTestSupport {
         Expression expression1 = 
context.resolveLanguage("simple").createExpression("${random( 10)}");
         assertTrue(0 <= expression1.evaluate(exchange, Integer.class) && 
expression1.evaluate(exchange, Integer.class) < max);
 
-        try {
-            assertExpression("${random(10,21,30)}", null);
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            assertEquals("Valid syntax: ${random(min,max)} or ${random(max)} 
was: random(10,21,30)", e.getCause().getMessage());
-        }
-        try {
-            assertExpression("${random()}", null);
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            assertEquals("Valid syntax: ${random(min,max)} or ${random(max)} 
was: random()", e.getCause().getMessage());
-        }
+        Exception e1 = assertThrows(Exception.class,
+                () -> assertExpression("${random(10,21,30)}", null),
+                "Should have thrown exception");
+
+        assertEquals("Valid syntax: ${random(min,max)} or ${random(max)} was: 
random(10,21,30)", e1.getCause().getMessage());
+
+        Exception e2 = assertThrows(Exception.class,
+                () -> assertExpression("${random()}", null),
+                "Should have thrown exception");
+
+        assertEquals("Valid syntax: ${random(min,max)} or ${random(max)} was: 
random()", e2.getCause().getMessage());
 
         exchange.getIn().setHeader("max", 20);
         Expression expression3 = 
context.resolveLanguage("simple").createExpression("${random(10,${header.max})}");

Reply via email to