This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
The following commit(s) were added to refs/heads/master by this push: new 5f18f663 Use Assertions.assertThrows() 5f18f663 is described below commit 5f18f6638d98950515b630412ddd9c9952f406a8 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Mon Sep 2 07:54:28 2024 -0400 Use Assertions.assertThrows() --- .../BeanPropertyValueChangeConsumerTestCase.java | 21 +++------------- .../BeanPropertyValueEqualsPredicateTestCase.java | 16 +++--------- .../BeanToPropertyValueTransformerTestCase.java | 29 +++++----------------- 3 files changed, 12 insertions(+), 54 deletions(-) diff --git a/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumerTestCase.java b/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumerTestCase.java index f5747d70..c932a6d1 100644 --- a/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumerTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumerTestCase.java @@ -50,12 +50,7 @@ public class BeanPropertyValueChangeConsumerTestCase { */ @Test public void testExecuteWithInvalidPropertyName() { - try { - new BeanPropertyValueChangeConsumer<>("bogusProperty", "foo").accept(new TestBean()); - fail("Should have thrown an IllegalArgumentException"); - } catch (final IllegalArgumentException e) { - /* this is what we expect */ - } + assertThrows(IllegalArgumentException.class, () -> new BeanPropertyValueChangeConsumer<>("bogusProperty", "foo").accept(new TestBean())); } /** @@ -293,12 +288,7 @@ public class BeanPropertyValueChangeConsumerTestCase { */ @Test public void testExecuteWithSimpleIntPropertyAndStringValue() { - try { - new BeanPropertyValueChangeConsumer<>("intProperty", "123").accept(new TestBean()); - fail("Should have thrown an IllegalArgumentException"); - } catch (final IllegalArgumentException e) { - /* this is what we expect */ - } + assertThrows(IllegalArgumentException.class, () -> new BeanPropertyValueChangeConsumer<>("intProperty", "123").accept(new TestBean())); } /** @@ -306,12 +296,7 @@ public class BeanPropertyValueChangeConsumerTestCase { */ @Test public void testExecuteWithSimplePrimitivePropertyAndNullValue() { - try { - new BeanPropertyValueChangeConsumer<>("intProperty", null).accept(new TestBean()); - fail("Should have thrown an IllegalArgumentException"); - } catch (final IllegalArgumentException e) { - /* this is what we expect */ - } + assertThrows(IllegalArgumentException.class, () -> new BeanPropertyValueChangeConsumer<>("intProperty", null).accept(new TestBean())); } /** diff --git a/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicateTestCase.java b/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicateTestCase.java index 3e1ae7eb..04d5d644 100644 --- a/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicateTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicateTestCase.java @@ -18,8 +18,8 @@ package org.apache.commons.beanutils2; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.Test; @@ -176,13 +176,7 @@ public class BeanPropertyValueEqualsPredicateTestCase { @Test public void testEvaluateWithNullInPath() { final BeanPropertyValueEqualsPredicate<TestBean, String> predicate = new BeanPropertyValueEqualsPredicate<>("anotherNested.stringProperty", "foo"); - try { - // try to evaluate the predicate - predicate.test(new TestBean()); - fail("Should have throw IllegalArgumentException"); - } catch (final IllegalArgumentException e) { - /* ignore this is what should happen */ - } + assertThrows(IllegalArgumentException.class, () -> predicate.test(new TestBean())); } /** @@ -192,11 +186,7 @@ public class BeanPropertyValueEqualsPredicateTestCase { public void testEvaluateWithNullInPathAndIgnoreTrue() { final BeanPropertyValueEqualsPredicate<TestBean, String> predicate = new BeanPropertyValueEqualsPredicate<>("anotherNested.stringProperty", "foo", true); - try { - assertFalse(predicate.test(new TestBean())); - } catch (final IllegalArgumentException e) { - fail("Should not have throw IllegalArgumentException"); - } + assertFalse(predicate.test(new TestBean())); } /** diff --git a/src/test/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformerTestCase.java b/src/test/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformerTestCase.java index 38ab7c18..6a32c758 100644 --- a/src/test/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformerTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformerTestCase.java @@ -19,7 +19,7 @@ package org.apache.commons.beanutils2; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.Test; @@ -40,20 +40,13 @@ public class BeanToPropertyValueTransformerTestCase { */ @Test public void testTransformWithIndexedProperty() { - BeanToPropertyValueTransformer<TestBean, Integer> transformer = new BeanToPropertyValueTransformer<>("intIndexed[0]"); + final BeanToPropertyValueTransformer<TestBean, Integer> transformer = new BeanToPropertyValueTransformer<>("intIndexed[0]"); final TestBean testBean = new TestBean(); testBean.setIntIndexed(0, expectedIntegerValue.intValue()); assertEquals(expectedIntegerValue, transformer.apply(testBean)); - // test index out of range - transformer = new BeanToPropertyValueTransformer<>("intIndexed[9999]"); - - try { - transformer.apply(testBean); - fail("Should have thrown an ArrayIndexOutOfBoundsException"); - } catch (final ArrayIndexOutOfBoundsException e) { - /* this is what should happen */ - } + final BeanToPropertyValueTransformer<TestBean, Integer> transformer2 = new BeanToPropertyValueTransformer<>("intIndexed[9999]"); + assertThrows(ArrayIndexOutOfBoundsException.class, () -> transformer2.apply(testBean)); } /** @@ -61,11 +54,7 @@ public class BeanToPropertyValueTransformerTestCase { */ @Test public void testTransformWithInvalidProperty() { - try { - new BeanToPropertyValueTransformer<>("bogusProperty").apply(new TestBean()); - } catch (final IllegalArgumentException e) { - /* This is what should happen */ - } + assertThrows(IllegalArgumentException.class, () -> new BeanToPropertyValueTransformer<>("bogusProperty").apply(new TestBean())); } /** @@ -116,13 +105,7 @@ public class BeanToPropertyValueTransformerTestCase { @Test public void testTransformWithNullInPath() { final BeanToPropertyValueTransformer<TestBean, String> transformer = new BeanToPropertyValueTransformer<>("anotherNested.stringProperty"); - - try { - transformer.apply(new TestBean()); - fail("Should have throw IllegalArgumentException"); - } catch (final IllegalArgumentException e) { - /* ignore this is what should happen */ - } + assertThrows(IllegalArgumentException.class, () -> transformer.apply(new TestBean())); } /**