mirror of
https://github.com/google/nomulus
synced 2026-08-01 04:46:08 +00:00
Get rid of custom ExceptionRule methods
The only remaining methods on ExceptionRule after this are methods that also exist on ExpectedException, which will allow us to, in the next CL, swap out the one for the other and then run the automated refactoring to turn it all into assertThrows/expectThrows. Note that there were some assertions about root causes that couldn't easily be turned into ExpectedException invocations, so I simply converted them directly to usages of assertThrows/expectThrows. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178623431
This commit is contained in:
@@ -16,7 +16,6 @@ package google.registry.testing;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Strings.nullToEmpty;
|
||||
import static com.google.common.base.Throwables.getRootCause;
|
||||
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
|
||||
|
||||
import google.registry.flows.EppException;
|
||||
@@ -37,8 +36,6 @@ public class ExceptionRule implements TestRule {
|
||||
@Nullable
|
||||
String expectedMessage;
|
||||
|
||||
private boolean useRootCause;
|
||||
|
||||
@Override
|
||||
public Statement apply(final Statement base, Description description) {
|
||||
return new Statement() {
|
||||
@@ -53,10 +50,9 @@ public class ExceptionRule implements TestRule {
|
||||
expectedMessage == null ? "" : (" with message: " + expectedMessage)));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Throwable cause = useRootCause ? getRootCause(e) : e;
|
||||
if (expectedExceptionClass == null
|
||||
|| !(expectedExceptionClass.isAssignableFrom(cause.getClass())
|
||||
&& nullToEmpty(cause.getMessage()).contains(nullToEmpty(expectedMessage)))) {
|
||||
|| !(expectedExceptionClass.isAssignableFrom(e.getClass())
|
||||
&& nullToEmpty(e.getMessage()).contains(nullToEmpty(expectedMessage)))) {
|
||||
throw e; // We didn't expect this so pass it through.
|
||||
}
|
||||
if (e instanceof EppException) {
|
||||
@@ -72,19 +68,7 @@ public class ExceptionRule implements TestRule {
|
||||
this.expectedExceptionClass = expectedExceptionClass;
|
||||
}
|
||||
|
||||
public void expect(Class<? extends Throwable> expectedExceptionClass, String expectedMessage) {
|
||||
expect(expectedExceptionClass);
|
||||
public void expectMessage(String expectedMessage) {
|
||||
this.expectedMessage = expectedMessage;
|
||||
}
|
||||
|
||||
public void expectRootCause(Class<? extends Throwable> expectedExceptionClass) {
|
||||
expect(expectedExceptionClass);
|
||||
this.useRootCause = true;
|
||||
}
|
||||
|
||||
public void expectRootCause(
|
||||
Class<? extends Throwable> expectedExceptionClass, String expectedMessage) {
|
||||
expect(expectedExceptionClass, expectedMessage);
|
||||
this.useRootCause = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user