mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +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,11 +15,10 @@
|
|||
package google.registry.tools.params;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -27,9 +26,6 @@ import org.junit.runners.JUnit4;
|
|||
@RunWith(JUnit4.class)
|
||||
public class DateParameterTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final DateParameter instance = new DateParameter();
|
||||
|
||||
@Test
|
||||
|
@ -40,61 +36,52 @@ public class DateParameterTest {
|
|||
|
||||
@Test
|
||||
public void testConvert_numeric_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("1234");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("1234"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_validDateAndTime_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("2014-01-01T01:02:03.004Z");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02:03.004Z"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_invalidDate_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("2014-13-33");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-13-33"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_null_throwsException() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
instance.convert(null);
|
||||
assertThrows(NullPointerException.class, () -> instance.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_empty_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_sillyString_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("foo");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_partialDate_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("2014-01");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_onlyTime_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("T01:02:03");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("T01:02:03"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_partialDateAndPartialTime_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("9T9");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("9T9"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_dateAndPartialTime_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("2014-01-01T01:02");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue