mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 17:59:41 +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
|
@ -15,12 +15,11 @@
|
|||
package google.registry.util;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.util.SerializeUtils.deserialize;
|
||||
import static google.registry.util.SerializeUtils.serialize;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -34,10 +33,6 @@ public class SerializeUtilsTest {
|
|||
return "LOL_VALUE";
|
||||
}
|
||||
}
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testSerialize_nullValue_returnsNull() throws Exception {
|
||||
assertThat(serialize(null)).isNull();
|
||||
|
@ -55,15 +50,17 @@ public class SerializeUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testSerialize_objectDoesntImplementSerialize_hasInformativeError() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Unable to serialize: LOL_VALUE");
|
||||
serialize(new Lol());
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> serialize(new Lol()));
|
||||
assertThat(thrown).hasMessageThat().contains("Unable to serialize: LOL_VALUE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize_badValue_hasInformativeError() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Unable to deserialize: objectBytes=FF");
|
||||
deserialize(String.class, new byte[] { (byte) 0xff });
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> deserialize(String.class, new byte[] {(byte) 0xff}));
|
||||
assertThat(thrown).hasMessageThat().contains("Unable to deserialize: objectBytes=FF");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue