mirror of
https://github.com/google/nomulus.git
synced 2025-07-21 10:16:07 +02:00
Migrate final try/catch test assertions to use assert/expectThrows
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=182091814
This commit is contained in:
parent
fe7cc4f782
commit
c416b3892d
17 changed files with 124 additions and 172 deletions
|
@ -15,12 +15,12 @@
|
|||
package google.registry.export;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.export.ExportReservedTermsAction.EXPORT_MIME_TYPE;
|
||||
import static google.registry.export.ExportReservedTermsAction.RESERVED_TERMS_FILENAME;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistReservedList;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
|
@ -123,26 +123,18 @@ public class ExportReservedTermsActionTest {
|
|||
any(MediaType.class),
|
||||
anyString(),
|
||||
any(byte[].class))).thenThrow(new IOException("errorMessage"));
|
||||
try {
|
||||
runAction("tld");
|
||||
assertWithMessage("Expected RuntimeException to be thrown").fail();
|
||||
} catch (RuntimeException e) {
|
||||
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
|
||||
assertThat(e).hasCauseThat().hasMessageThat().isEqualTo("errorMessage");
|
||||
}
|
||||
RuntimeException thrown = expectThrows(RuntimeException.class, () -> runAction("tld"));
|
||||
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
|
||||
assertThat(thrown).hasCauseThat().hasMessageThat().isEqualTo("errorMessage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_uploadFileToDrive_failsWhenTldDoesntExist() throws Exception {
|
||||
try {
|
||||
runAction("fakeTld");
|
||||
assertWithMessage("Expected RuntimeException to be thrown").fail();
|
||||
} catch (RuntimeException e) {
|
||||
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
|
||||
assertThat(e)
|
||||
.hasCauseThat()
|
||||
.hasMessageThat()
|
||||
.isEqualTo("No registry object found for fakeTld");
|
||||
}
|
||||
RuntimeException thrown = expectThrows(RuntimeException.class, () -> runAction("fakeTld"));
|
||||
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
|
||||
assertThat(thrown)
|
||||
.hasCauseThat()
|
||||
.hasMessageThat()
|
||||
.isEqualTo("No registry object found for fakeTld");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue