From 03dd45fbd62bdc158bf31098fd54cf5de3da2026 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 6 Aug 2019 18:18:16 +0200 Subject: [PATCH] Use AssertJ in AnnotationAttributesTests --- .../annotation/AnnotationAttributesTests.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java index fd23536d289..a41e43c9e5f 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java @@ -74,17 +74,19 @@ public class AnnotationAttributesTests { @Test public void unresolvableClassWithClassNotFoundException() throws Exception { attributes.put("unresolvableClass", new ClassNotFoundException("myclass")); - assertThatIllegalArgumentException().isThrownBy(() -> - attributes.getClass("unresolvableClass")) - .withMessageContaining("myclass"); + assertThatIllegalArgumentException() + .isThrownBy(() -> attributes.getClass("unresolvableClass")) + .withMessageContaining("myclass") + .withCauseInstanceOf(ClassNotFoundException.class); } @Test public void unresolvableClassWithLinkageError() throws Exception { attributes.put("unresolvableClass", new LinkageError("myclass")); - exception.expect(IllegalArgumentException.class); - exception.expectMessage(containsString("myclass")); - attributes.getClass("unresolvableClass"); + assertThatIllegalArgumentException() + .isThrownBy(() -> attributes.getClass("unresolvableClass")) + .withMessageContaining("myclass") + .withCauseInstanceOf(LinkageError.class); } @Test @@ -134,30 +136,30 @@ public class AnnotationAttributesTests { @Test public void getEnumWithNullAttributeName() { - assertThatIllegalArgumentException().isThrownBy(() -> - attributes.getEnum(null)) + assertThatIllegalArgumentException() + .isThrownBy(() -> attributes.getEnum(null)) .withMessageContaining("must not be null or empty"); } @Test public void getEnumWithEmptyAttributeName() { - assertThatIllegalArgumentException().isThrownBy(() -> - attributes.getEnum("")) + assertThatIllegalArgumentException() + .isThrownBy(() -> attributes.getEnum("")) .withMessageContaining("must not be null or empty"); } @Test public void getEnumWithUnknownAttributeName() { - assertThatIllegalArgumentException().isThrownBy(() -> - attributes.getEnum("bogus")) + assertThatIllegalArgumentException() + .isThrownBy(() -> attributes.getEnum("bogus")) .withMessageContaining("Attribute 'bogus' not found"); } @Test public void getEnumWithTypeMismatch() { attributes.put("color", "RED"); - assertThatIllegalArgumentException().isThrownBy(() -> - attributes.getEnum("color")) + assertThatIllegalArgumentException() + .isThrownBy(() -> attributes.getEnum("color")) .withMessageContaining("Attribute 'color' is of type String, but Enum was expected"); }