mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +02:00
Move thrown.expect() right before the throwing statement
aka regexing for fun and profit. This also makes sure that there are no statements after the throwing statement, since these would be dead code. There were a surprising number of places with assertions after the throw, and none of these are actually triggered in tests ever. When I found these, I replaced them with try/catch/rethrow which makes the assertions actually happen: before: // This is the ExceptionRule that checks EppException marshaling thrown.expect(FooException.class); doThrowingThing(); assertSomething(); // Dead code! after: try { doThrowingThing(); assertWithMessage("...").fail(); } catch (FooException e) { assertSomething(); // For EppExceptions: assertAboutEppExceptins().that(e).marshalsToXml(); } To make this work, I added EppExceptionSubject. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=135793407
This commit is contained in:
parent
cb8320ff40
commit
f3a0b78145
62 changed files with 519 additions and 450 deletions
|
@ -17,15 +17,9 @@ 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.flows.EppXmlTransformer.marshal;
|
||||
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
|
||||
|
||||
import google.registry.flows.EppException;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.eppoutput.EppOutput;
|
||||
import google.registry.model.eppoutput.EppResponse;
|
||||
import google.registry.util.Clock;
|
||||
import google.registry.util.SystemClock;
|
||||
import google.registry.xml.ValidationMode;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
|
@ -37,8 +31,6 @@ import org.junit.runners.model.Statement;
|
|||
*/
|
||||
public class ExceptionRule implements TestRule {
|
||||
|
||||
private static final Clock CLOCK = new SystemClock();
|
||||
|
||||
@Nullable
|
||||
Class<? extends Throwable> expectedExceptionClass;
|
||||
|
||||
|
@ -68,14 +60,7 @@ public class ExceptionRule implements TestRule {
|
|||
throw e; // We didn't expect this so pass it through.
|
||||
}
|
||||
if (e instanceof EppException) {
|
||||
// Attempt to marshall the exception to EPP. If it doesn't work, this will throw.
|
||||
marshal(
|
||||
EppOutput.create(new EppResponse.Builder()
|
||||
.setTrid(Trid.create(null))
|
||||
.setResult(((EppException) e).getResult())
|
||||
.setExecutionTime(CLOCK.nowUtc())
|
||||
.build()),
|
||||
ValidationMode.STRICT);
|
||||
assertAboutEppExceptions().that((EppException) e).marshalsToXml();
|
||||
}
|
||||
}
|
||||
}};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue