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:
@@ -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 {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user