Browse Source

Use AssertJ in AnnotationAttributesTests

pull/23435/head
Sam Brannen 7 years ago
parent
commit
03dd45fbd6
  1. 30
      spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java

30
spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java

@ -74,17 +74,19 @@ public class AnnotationAttributesTests {
@Test @Test
public void unresolvableClassWithClassNotFoundException() throws Exception { public void unresolvableClassWithClassNotFoundException() throws Exception {
attributes.put("unresolvableClass", new ClassNotFoundException("myclass")); attributes.put("unresolvableClass", new ClassNotFoundException("myclass"));
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException()
attributes.getClass("unresolvableClass")) .isThrownBy(() -> attributes.getClass("unresolvableClass"))
.withMessageContaining("myclass"); .withMessageContaining("myclass")
.withCauseInstanceOf(ClassNotFoundException.class);
} }
@Test @Test
public void unresolvableClassWithLinkageError() throws Exception { public void unresolvableClassWithLinkageError() throws Exception {
attributes.put("unresolvableClass", new LinkageError("myclass")); attributes.put("unresolvableClass", new LinkageError("myclass"));
exception.expect(IllegalArgumentException.class); assertThatIllegalArgumentException()
exception.expectMessage(containsString("myclass")); .isThrownBy(() -> attributes.getClass("unresolvableClass"))
attributes.getClass("unresolvableClass"); .withMessageContaining("myclass")
.withCauseInstanceOf(LinkageError.class);
} }
@Test @Test
@ -134,30 +136,30 @@ public class AnnotationAttributesTests {
@Test @Test
public void getEnumWithNullAttributeName() { public void getEnumWithNullAttributeName() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException()
attributes.getEnum(null)) .isThrownBy(() -> attributes.getEnum(null))
.withMessageContaining("must not be null or empty"); .withMessageContaining("must not be null or empty");
} }
@Test @Test
public void getEnumWithEmptyAttributeName() { public void getEnumWithEmptyAttributeName() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException()
attributes.getEnum("")) .isThrownBy(() -> attributes.getEnum(""))
.withMessageContaining("must not be null or empty"); .withMessageContaining("must not be null or empty");
} }
@Test @Test
public void getEnumWithUnknownAttributeName() { public void getEnumWithUnknownAttributeName() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException()
attributes.getEnum("bogus")) .isThrownBy(() -> attributes.getEnum("bogus"))
.withMessageContaining("Attribute 'bogus' not found"); .withMessageContaining("Attribute 'bogus' not found");
} }
@Test @Test
public void getEnumWithTypeMismatch() { public void getEnumWithTypeMismatch() {
attributes.put("color", "RED"); attributes.put("color", "RED");
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException()
attributes.getEnum("color")) .isThrownBy(() -> attributes.getEnum("color"))
.withMessageContaining("Attribute 'color' is of type String, but Enum was expected"); .withMessageContaining("Attribute 'color' is of type String, but Enum was expected");
} }

Loading…
Cancel
Save