Fix compatibility with JUnit's ExpectedException

This commit ensures that an exception that is thrown as part of the
`ContextConsumer` callback is thrown as is.

Closes gh-9878
This commit is contained in:
Stephane Nicoll
2017-07-27 11:08:01 +02:00
parent 7532876efc
commit eacb6b13f3
3 changed files with 42 additions and 6 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.boot.test.context.runner;
import java.io.IOException;
import java.util.UUID;
import com.google.gson.Gson;
@@ -161,8 +162,21 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
});
}
@Test
public void thrownRuleWorksWithCheckedException() {
get().run((context) -> {
this.thrown.expect(IOException.class);
this.thrown.expectMessage("Expected message");
throwCheckedException("Expected message");
});
}
protected abstract T get();
private static void throwCheckedException(String message) throws IOException {
throw new IOException(message);
}
@Configuration
static class FailingConfig {