Skip to content

Commit c8636bd

Browse files
committed
JUnit assertThrows FailingTestCase
1 parent 3d4068d commit c8636bd

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

core/src/test/java/org/apache/commons/digester3/annotations/failingtests/FailingTestCase.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
package org.apache.commons.digester3.annotations.failingtests;
1919

2020
import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
21+
import static org.hamcrest.MatcherAssert.assertThat;
22+
import static org.hamcrest.core.Is.is;
23+
import static org.hamcrest.core.StringStartsWith.startsWith;
24+
import static org.junit.jupiter.api.Assertions.assertThrows;
2125

2226
import org.apache.commons.digester3.annotations.FromAnnotationsRuleModule;
2327
import org.apache.commons.digester3.binder.DigesterLoadingException;
@@ -29,20 +33,20 @@ public final class FailingTestCase
2933
/**
3034
* Tests to make sure loader fails
3135
*/
32-
@Test(expected = DigesterLoadingException.class)
36+
@Test
3337
public void failsBecauseFailingDigesterLoaderHandlerFactory() {
3438

35-
newLoader(new FromAnnotationsRuleModule()
36-
{
39+
final DigesterLoadingException thrown = assertThrows(DigesterLoadingException.class, () ->
40+
newLoader(new FromAnnotationsRuleModule() {
3741

38-
@Override
39-
protected void configureRules()
40-
{
41-
useAnnotationHandlerFactory( new FailingDigesterLoaderHandlerFactory() );
42-
bindRulesFrom( BeanWithFakeHandler.class );
43-
}
42+
@Override
43+
protected void configureRules() {
44+
useAnnotationHandlerFactory(new FailingDigesterLoaderHandlerFactory());
45+
bindRulesFrom(BeanWithFakeHandler.class);
46+
}
4447

45-
}).newDigester();
48+
}).newDigester());
49+
assertThat(thrown.getMessage(), is(startsWith("Digester creation errors:")));
4650
}
4751

4852
}

0 commit comments

Comments
 (0)