Use AssertJ in AnnotationAttributesTests

This commit is contained in:
Sam Brannen 2019-08-06 18:18:16 +02:00
parent 34767b14da
commit 03dd45fbd6
1 changed files with 16 additions and 14 deletions

View File

@ -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");
} }