mirror of
https://github.com/google/nomulus.git
synced 2025-08-01 23:42:12 +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"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,23 +15,19 @@
|
|||
package google.registry.tools.params;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.beust.jcommander.ParameterException;
|
||||
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;
|
||||
|
||||
/** Unit tests for {@link DateTimeParameter}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class DateTimeParameterTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final DateTimeParameter instance = new DateTimeParameter();
|
||||
|
||||
@Test
|
||||
|
@ -60,69 +56,59 @@ public class DateTimeParameterTest {
|
|||
|
||||
@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_onlyDate_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("2014-01-01");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_partialTime_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("T01:02");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("T01:02"));
|
||||
}
|
||||
|
||||
@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"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_noTimeZone_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("2014-01-01T01:02:03");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02:03"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidate_sillyString_throwsParameterException() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expectMessage("--time=foo not an ISO");
|
||||
instance.validate("--time", "foo");
|
||||
ParameterException thrown =
|
||||
expectThrows(ParameterException.class, () -> instance.validate("--time", "foo"));
|
||||
assertThat(thrown).hasMessageThat().contains("--time=foo not an ISO");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -15,23 +15,19 @@
|
|||
package google.registry.tools.params;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.beust.jcommander.ParameterException;
|
||||
import org.joda.time.Duration;
|
||||
import org.joda.time.Period;
|
||||
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 {@link DurationParameter}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class DurationParameterTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final DurationParameter instance = new DurationParameter();
|
||||
|
||||
@Test
|
||||
|
@ -51,50 +47,43 @@ public class DurationParameterTest {
|
|||
|
||||
@Test
|
||||
public void testIsoMissingP_notAllowed() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
Period.parse("T36H");
|
||||
assertThrows(IllegalArgumentException.class, () -> Period.parse("T36H"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsoMissingPT_notAllowed() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
Period.parse("36H");
|
||||
assertThrows(IllegalArgumentException.class, () -> Period.parse("36H"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_isoMissingP_notAllowed() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("T36H");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("T36H"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_null_throws() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
instance.convert(null);
|
||||
assertThrows(NullPointerException.class, () -> instance.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_empty_throws() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_numeric_throws() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("1234");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("1234"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_sillyString_throws() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("foo");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidate_sillyString_throws() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expectMessage("--time=foo not an");
|
||||
instance.validate("--time", "foo");
|
||||
ParameterException thrown =
|
||||
expectThrows(ParameterException.class, () -> instance.validate("--time", "foo"));
|
||||
assertThat(thrown).hasMessageThat().contains("--time=foo not an");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,11 +15,10 @@
|
|||
package google.registry.tools.params;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import google.registry.model.registry.Registry.TldState;
|
||||
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 EnumParameterTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
// There's no additional functionality exposed by this (or any other) EnumParameter, but using
|
||||
// this in the test as EnumParameter is abstract.
|
||||
private final TldStateParameter instance = new TldStateParameter();
|
||||
|
@ -41,9 +37,11 @@ public class EnumParameterTest {
|
|||
|
||||
@Test
|
||||
public void testFailure_badValue() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage(
|
||||
"No enum constant google.registry.model.registry.Registry.TldState.GENERAL_SUNRUSH");
|
||||
instance.convert("GENERAL_SUNRUSH");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> instance.convert("GENERAL_SUNRUSH"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
"No enum constant google.registry.model.registry.Registry.TldState.GENERAL_SUNRUSH");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,23 +15,19 @@
|
|||
package google.registry.tools.params;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.beust.jcommander.ParameterException;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Interval;
|
||||
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 {@link IntervalParameter}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class IntervalParameterTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final IntervalParameter instance = new IntervalParameter();
|
||||
|
||||
@Test
|
||||
|
@ -44,38 +40,35 @@ public class IntervalParameterTest {
|
|||
|
||||
@Test
|
||||
public void testConvert_singleDate() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("2004-06-09T12:30:00Z");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("2004-06-09T12:30:00Z"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_backwardsInterval() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("2004-07-10T13:30:00Z/2004-06-09T12:30:00Z");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> instance.convert("2004-07-10T13:30:00Z/2004-06-09T12:30:00Z"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_empty_throws() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_null_throws() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
instance.convert(null);
|
||||
assertThrows(NullPointerException.class, () -> instance.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_sillyString_throws() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("foo");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidate_sillyString_throws() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expectMessage("--time=foo not an");
|
||||
instance.validate("--time", "foo");
|
||||
ParameterException thrown =
|
||||
expectThrows(ParameterException.class, () -> instance.validate("--time", "foo"));
|
||||
assertThat(thrown).hasMessageThat().contains("--time=foo not an");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
package google.registry.tools.params;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.tools.params.KeyValueMapParameter.CurrencyUnitToStringMap;
|
||||
|
@ -22,19 +24,13 @@ import google.registry.tools.params.KeyValueMapParameter.StringToIntegerMap;
|
|||
import google.registry.tools.params.KeyValueMapParameter.StringToStringMap;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.joda.money.IllegalCurrencyException;
|
||||
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 {@link KeyValueMapParameter}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class KeyValueMapParameterTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final StringToStringMap stringToStringInstance = new StringToStringMap();
|
||||
private final StringToIntegerMap stringToIntegerInstance = new StringToIntegerMap();
|
||||
private final CurrencyUnitToStringMap currencyUnitToStringMap = new CurrencyUnitToStringMap();
|
||||
|
@ -92,51 +88,51 @@ public class KeyValueMapParameterTest {
|
|||
|
||||
@Test
|
||||
public void testFailure_convertStringToInteger_badType() throws Exception {
|
||||
thrown.expect(NumberFormatException.class);
|
||||
stringToIntegerInstance.convert("key=1,key2=foo");
|
||||
assertThrows(
|
||||
NumberFormatException.class, () -> stringToIntegerInstance.convert("key=1,key2=foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_convertCurrencyUnitToString_badType() throws Exception {
|
||||
thrown.expect(IllegalCurrencyException.class);
|
||||
thrown.expectMessage("XYZ");
|
||||
currencyUnitToStringMap.convert("USD=123abc,XYZ=xyz789");
|
||||
IllegalCurrencyException thrown =
|
||||
expectThrows(
|
||||
IllegalCurrencyException.class,
|
||||
() -> currencyUnitToStringMap.convert("USD=123abc,XYZ=xyz789"));
|
||||
assertThat(thrown).hasMessageThat().contains("XYZ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_convertStringToString_badSeparator() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
stringToStringInstance.convert("key=foo&key2=bar");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> stringToStringInstance.convert("key=foo&key2=bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_convertStringToInteger_badSeparator() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
stringToIntegerInstance.convert("key=1&key2=2");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> stringToIntegerInstance.convert("key=1&key2=2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_convertCurrencyUnitToString_badSeparator() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
currencyUnitToStringMap.convert("USD=123abc&JPY=xyz789");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> currencyUnitToStringMap.convert("USD=123abc&JPY=xyz789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_convertStringToString_badFormat() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
stringToStringInstance.convert("foo");
|
||||
assertThrows(IllegalArgumentException.class, () -> stringToStringInstance.convert("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_convertStringToInteger_badFormat() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
stringToIntegerInstance.convert("foo");
|
||||
assertThrows(IllegalArgumentException.class, () -> stringToIntegerInstance.convert("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_convertCurrencyUnitToString_badFormat() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
currencyUnitToStringMap.convert("foo");
|
||||
assertThrows(IllegalArgumentException.class, () -> currencyUnitToStringMap.convert("foo"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,22 +15,18 @@
|
|||
package google.registry.tools.params;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.beust.jcommander.ParameterException;
|
||||
import org.joda.money.Money;
|
||||
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 {@link MoneyParameter}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class MoneyParameterTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final MoneyParameter instance = new MoneyParameter();
|
||||
|
||||
@Test
|
||||
|
@ -55,33 +51,29 @@ public class MoneyParameterTest {
|
|||
|
||||
@Test
|
||||
public void testConvert_badCurrency_throws() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("FOO 1337");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("FOO 1337"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_null_throws() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
instance.convert(null);
|
||||
assertThrows(NullPointerException.class, () -> instance.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_empty_throws() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_sillyString_throws() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("foo");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidate_sillyString_throws() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expectMessage("--money=foo not valid");
|
||||
instance.validate("--money", "foo");
|
||||
ParameterException thrown =
|
||||
expectThrows(ParameterException.class, () -> instance.validate("--money", "foo"));
|
||||
assertThat(thrown).hasMessageThat().contains("--money=foo not valid");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
package google.registry.tools.params;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
@ -31,7 +33,6 @@ import java.nio.file.Paths;
|
|||
import java.nio.file.attribute.PosixFilePermissions;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
@ -39,10 +40,6 @@ import org.junit.runners.JUnit4;
|
|||
/** Unit tests for {@link PathParameter}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class PathParameterTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public final TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
|
@ -57,14 +54,12 @@ public class PathParameterTest {
|
|||
|
||||
@Test
|
||||
public void testConvert_null_throws() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
vanilla.convert(null);
|
||||
assertThrows(NullPointerException.class, () -> vanilla.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_empty_throws() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
vanilla.convert("");
|
||||
assertThrows(IllegalArgumentException.class, () -> vanilla.convert(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -86,8 +81,7 @@ public class PathParameterTest {
|
|||
|
||||
@Test
|
||||
public void testConvert_uriNotProvided() throws Exception {
|
||||
thrown.expect(FileSystemNotFoundException.class);
|
||||
vanilla.convert("bog://bucket/lolcat");
|
||||
assertThrows(FileSystemNotFoundException.class, () -> vanilla.convert("bog://bucket/lolcat"));
|
||||
}
|
||||
|
||||
// =========================== Test InputFile Validate ========================================
|
||||
|
@ -101,25 +95,29 @@ public class PathParameterTest {
|
|||
|
||||
@Test
|
||||
public void testInputFileValidate_missingFile_throws() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expectMessage("not found");
|
||||
inputFile.validate("input", new File(folder.getRoot(), "foo").toString());
|
||||
ParameterException thrown =
|
||||
expectThrows(
|
||||
ParameterException.class,
|
||||
() -> inputFile.validate("input", new File(folder.getRoot(), "foo").toString()));
|
||||
assertThat(thrown).hasMessageThat().contains("not found");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputFileValidate_directory_throws() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expectMessage("is a directory");
|
||||
inputFile.validate("input", folder.getRoot().toString());
|
||||
ParameterException thrown =
|
||||
expectThrows(
|
||||
ParameterException.class,
|
||||
() -> inputFile.validate("input", folder.getRoot().toString()));
|
||||
assertThat(thrown).hasMessageThat().contains("is a directory");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputFileValidate_unreadableFile_throws() throws Exception {
|
||||
Path file = Paths.get(folder.newFile().toString());
|
||||
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("-w-------"));
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expectMessage("not readable");
|
||||
inputFile.validate("input", file.toString());
|
||||
ParameterException thrown =
|
||||
expectThrows(ParameterException.class, () -> inputFile.validate("input", file.toString()));
|
||||
assertThat(thrown).hasMessageThat().contains("not readable");
|
||||
}
|
||||
|
||||
// =========================== Test OutputFile Validate ========================================
|
||||
|
@ -144,33 +142,35 @@ public class PathParameterTest {
|
|||
|
||||
@Test
|
||||
public void testOutputFileValidate_directory_throws() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expectMessage("is a directory");
|
||||
outputFile.validate("input", folder.getRoot().toString());
|
||||
ParameterException thrown =
|
||||
expectThrows(
|
||||
ParameterException.class,
|
||||
() -> outputFile.validate("input", folder.getRoot().toString()));
|
||||
assertThat(thrown).hasMessageThat().contains("is a directory");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputFileValidate_notWritable_throws() throws Exception {
|
||||
Path file = Paths.get(folder.newFile().toString());
|
||||
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("r--------"));
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expectMessage("not writable");
|
||||
outputFile.validate("input", file.toString());
|
||||
ParameterException thrown =
|
||||
expectThrows(ParameterException.class, () -> outputFile.validate("input", file.toString()));
|
||||
assertThat(thrown).hasMessageThat().contains("not writable");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputFileValidate_parentDirMissing_throws() throws Exception {
|
||||
Path file = Paths.get(folder.getRoot().toString(), "MISSINGNO", "foo.txt");
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expectMessage("parent dir doesn't exist");
|
||||
outputFile.validate("input", file.toString());
|
||||
ParameterException thrown =
|
||||
expectThrows(ParameterException.class, () -> outputFile.validate("input", file.toString()));
|
||||
assertThat(thrown).hasMessageThat().contains("parent dir doesn't exist");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputFileValidate_parentDirIsFile_throws() throws Exception {
|
||||
Path file = Paths.get(folder.newFile().toString(), "foo.txt");
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expectMessage("parent is non-directory");
|
||||
outputFile.validate("input", file.toString());
|
||||
ParameterException thrown =
|
||||
expectThrows(ParameterException.class, () -> outputFile.validate("input", file.toString()));
|
||||
assertThat(thrown).hasMessageThat().contains("parent is non-directory");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,20 +15,15 @@
|
|||
package google.registry.tools.params;
|
||||
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
|
||||
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 {@link PhoneNumberParameter}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class PhoneNumberParameterTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final OptionalPhoneNumberParameter instance = new OptionalPhoneNumberParameter();
|
||||
|
||||
@Test
|
||||
|
@ -38,8 +33,7 @@ public class PhoneNumberParameterTest {
|
|||
|
||||
@Test
|
||||
public void testConvert_sillyString_throws() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("foo");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -15,22 +15,18 @@
|
|||
package google.registry.tools.params;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.beust.jcommander.ParameterException;
|
||||
import org.joda.time.YearMonth;
|
||||
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 {@link YearMonthParameter}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class YearMonthParameterTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final YearMonthParameter instance = new YearMonthParameter();
|
||||
|
||||
@Test
|
||||
|
@ -40,39 +36,34 @@ public class YearMonthParameterTest {
|
|||
|
||||
@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_wrongOrder() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("12-1984");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("12-1984"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_noHyphen() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
instance.convert("198412");
|
||||
assertThrows(IllegalArgumentException.class, () -> instance.convert("198412"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidate_sillyString_throwsParameterException() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expectMessage("--time=foo not a valid");
|
||||
instance.validate("--time", "foo");
|
||||
ParameterException thrown =
|
||||
expectThrows(ParameterException.class, () -> instance.validate("--time", "foo"));
|
||||
assertThat(thrown).hasMessageThat().contains("--time=foo not a valid");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -32,7 +32,6 @@ import google.registry.testing.InjectRule;
|
|||
import java.util.Optional;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -46,10 +45,6 @@ public class CreateGroupsActionTest {
|
|||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
|
@ -67,17 +62,21 @@ public class CreateGroupsActionTest {
|
|||
|
||||
@Test
|
||||
public void test_invalidRequest_missingClientId() throws Exception {
|
||||
thrown.expect(BadRequestException.class);
|
||||
thrown.expectMessage("Error creating Google Groups, missing parameter: clientId");
|
||||
runAction(null);
|
||||
BadRequestException thrown = expectThrows(BadRequestException.class, () -> runAction(null));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Error creating Google Groups, missing parameter: clientId");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_invalidRequest_invalidClientId() throws Exception {
|
||||
thrown.expect(BadRequestException.class);
|
||||
thrown.expectMessage(
|
||||
"Error creating Google Groups; could not find registrar with id completelyMadeUpClientId");
|
||||
runAction("completelyMadeUpClientId");
|
||||
BadRequestException thrown =
|
||||
expectThrows(BadRequestException.class, () -> runAction("completelyMadeUpClientId"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
"Error creating Google Groups; "
|
||||
+ "could not find registrar with id completelyMadeUpClientId");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.joda.money.Money;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -41,8 +40,6 @@ import org.junit.runners.JUnit4;
|
|||
public class CreatePremiumListActionTest {
|
||||
|
||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
CreatePremiumListAction action;
|
||||
FakeJsonResponse response;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import static com.google.appengine.api.datastore.DatastoreServiceFactory.getData
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.googlecode.objectify.Key.create;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.appengine.api.datastore.Entity;
|
||||
import com.google.appengine.api.datastore.KeyFactory;
|
||||
|
@ -28,7 +29,6 @@ import google.registry.testing.FakeResponse;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -38,10 +38,6 @@ public class DeleteEntityActionTest {
|
|||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
FakeResponse response = new FakeResponse();
|
||||
DeleteEntityAction action = new DeleteEntityAction();
|
||||
|
||||
|
@ -89,9 +85,8 @@ public class DeleteEntityActionTest {
|
|||
Entity entity = new Entity("not", "here");
|
||||
String rawKey = KeyFactory.keyToString(entity.getKey());
|
||||
action.rawKeys = rawKey;
|
||||
thrown.expect(BadRequestException.class);
|
||||
thrown.expectMessage("Could not find entity with key " + rawKey);
|
||||
action.run();
|
||||
BadRequestException thrown = expectThrows(BadRequestException.class, () -> action.run());
|
||||
assertThat(thrown).hasMessageThat().contains("Could not find entity with key " + rawKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -102,8 +97,7 @@ public class DeleteEntityActionTest {
|
|||
Entity entity = new Entity("non", "existent");
|
||||
String rawKey = KeyFactory.keyToString(entity.getKey());
|
||||
action.rawKeys = String.format("%s,%s", ofyKey, rawKey);
|
||||
thrown.expect(BadRequestException.class);
|
||||
thrown.expectMessage("Could not find entity with key " + rawKey);
|
||||
action.run();
|
||||
BadRequestException thrown = expectThrows(BadRequestException.class, () -> action.run());
|
||||
assertThat(thrown).hasMessageThat().contains("Could not find entity with key " + rawKey);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Base class for tests of list actions.
|
||||
|
@ -35,9 +34,6 @@ public class ListActionTestCase {
|
|||
.withDatastore()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private FakeJsonResponse response;
|
||||
|
||||
private void runAction(
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.joda.money.Money;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -44,9 +43,6 @@ public class UpdatePremiumListActionTest {
|
|||
.withDatastore()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
UpdatePremiumListAction action;
|
||||
FakeJsonResponse response;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue