Skip to content

Commit 7dcc0e1

Browse files
committed
JUnit assertThrows FailingTestCase
1 parent ba2556a commit 7dcc0e1

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,41 @@
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;
2428
import org.junit.Test;
29+
import org.junit.jupiter.api.function.Executable;
2530

2631
public final class FailingTestCase
2732
{
2833

2934
/**
3035
* Tests to make sure loader fails
3136
*/
32-
@Test(expected = DigesterLoadingException.class)
37+
@Test
3338
public void failsBecauseFailingDigesterLoaderHandlerFactory() {
3439

35-
newLoader(new FromAnnotationsRuleModule()
36-
{
40+
// FIXME Simplification once upgraded to Java 1.8 and use lambda
41+
final Executable testMethod = new Executable() {
42+
public void execute() throws Throwable {
43+
newLoader(new FromAnnotationsRuleModule() {
3744

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

45-
}).newDigester();
51+
}).newDigester();
52+
}
53+
};
54+
final DigesterLoadingException thrown = assertThrows(DigesterLoadingException.class, testMethod);
55+
assertThat(thrown.getMessage(), is(startsWith("Digester creation errors:")));
4656
}
4757

4858
}

0 commit comments

Comments
 (0)