mirror of
https://github.com/google/nomulus.git
synced 2025-06-02 02:28:40 +02:00
Automatically refactor more exception testing to use new JUnit rules
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178911894
This commit is contained in:
parent
36ad38e5df
commit
7dc224627f
125 changed files with 1970 additions and 1982 deletions
|
@ -16,6 +16,7 @@ package google.registry.xjc;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
||||
import static google.registry.xjc.XjcXmlTransformer.unmarshal;
|
||||
import static java.nio.charset.StandardCharsets.UTF_16;
|
||||
|
@ -27,19 +28,13 @@ import google.registry.xjc.rde.XjcRdeDepositTypeType;
|
|||
import google.registry.xjc.rdecontact.XjcRdeContact;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@code XjcObject}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class XjcObjectTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private static final String RDE_DEPOSIT_FULL =
|
||||
readResourceUtf8(XjcObjectTest.class, "testdata/rde_deposit_full.xml");
|
||||
|
||||
|
@ -69,9 +64,9 @@ public class XjcObjectTest {
|
|||
public void testMarshalValidation() throws Exception {
|
||||
XjcRdeDeposit deposit = unmarshalFullDeposit();
|
||||
deposit.setId("");
|
||||
thrown.expect(Throwable.class);
|
||||
thrown.expectMessage("pattern '\\w{1,13}' for type 'depositIdType'");
|
||||
deposit.marshal(new ByteArrayOutputStream(), UTF_8);
|
||||
Throwable thrown =
|
||||
expectThrows(Throwable.class, () -> deposit.marshal(new ByteArrayOutputStream(), UTF_8));
|
||||
assertThat(thrown).hasMessageThat().contains("pattern '\\w{1,13}' for type 'depositIdType'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -93,10 +88,17 @@ public class XjcObjectTest {
|
|||
|
||||
@Test
|
||||
public void testUnmarshalValidation() throws Exception {
|
||||
thrown.expect(Throwable.class);
|
||||
thrown.expectMessage("pattern '\\w{1,13}' for type 'depositIdType'");
|
||||
unmarshal(XjcRdeDeposit.class, new ByteArrayInputStream(
|
||||
RDE_DEPOSIT_FULL.replaceFirst("id=\"[^\"]+\"", "id=\"\"").getBytes(UTF_8)));
|
||||
Throwable thrown =
|
||||
expectThrows(
|
||||
Throwable.class,
|
||||
() ->
|
||||
unmarshal(
|
||||
XjcRdeDeposit.class,
|
||||
new ByteArrayInputStream(
|
||||
RDE_DEPOSIT_FULL
|
||||
.replaceFirst("id=\"[^\"]+\"", "id=\"\"")
|
||||
.getBytes(UTF_8))));
|
||||
assertThat(thrown).hasMessageThat().contains("pattern '\\w{1,13}' for type 'depositIdType'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue