Upgrade rest of tools test classes to JUnit 5 (#705)

This commit is contained in:
Ben McIlwain 2020-07-22 11:09:21 -04:00 committed by GitHub
parent 0385d968db
commit 92e3b0b61d
27 changed files with 308 additions and 384 deletions

View file

@ -18,70 +18,67 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link DateParameter}. */ /** Unit tests for {@link DateParameter}. */
@RunWith(JUnit4.class) class DateParameterTest {
public class DateParameterTest {
private final DateParameter instance = new DateParameter(); private final DateParameter instance = new DateParameter();
@Test @Test
public void testConvert_onlyDate() { void testConvert_onlyDate() {
String exampleDate = "2014-01-01"; String exampleDate = "2014-01-01";
assertThat(instance.convert(exampleDate)).isEqualTo(DateTime.parse("2014-01-01T00:00:00Z")); assertThat(instance.convert(exampleDate)).isEqualTo(DateTime.parse("2014-01-01T00:00:00Z"));
} }
@Test @Test
public void testConvert_numeric_throwsException() { void testConvert_numeric_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("1234")); assertThrows(IllegalArgumentException.class, () -> instance.convert("1234"));
} }
@Test @Test
public void testConvert_validDateAndTime_throwsException() { void testConvert_validDateAndTime_throwsException() {
assertThrows( assertThrows(
IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02:03.004Z")); IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02:03.004Z"));
} }
@Test @Test
public void testConvert_invalidDate_throwsException() { void testConvert_invalidDate_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-13-33")); assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-13-33"));
} }
@Test @Test
public void testConvert_null_throwsException() { void testConvert_null_throwsException() {
assertThrows(NullPointerException.class, () -> instance.convert(null)); assertThrows(NullPointerException.class, () -> instance.convert(null));
} }
@Test @Test
public void testConvert_empty_throwsException() { void testConvert_empty_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("")); assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
} }
@Test @Test
public void testConvert_sillyString_throwsException() { void testConvert_sillyString_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo")); assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
} }
@Test @Test
public void testConvert_partialDate_throwsException() { void testConvert_partialDate_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01")); assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01"));
} }
@Test @Test
public void testConvert_onlyTime_throwsException() { void testConvert_onlyTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("T01:02:03")); assertThrows(IllegalArgumentException.class, () -> instance.convert("T01:02:03"));
} }
@Test @Test
public void testConvert_partialDateAndPartialTime_throwsException() { void testConvert_partialDateAndPartialTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("9T9")); assertThrows(IllegalArgumentException.class, () -> instance.convert("9T9"));
} }
@Test @Test
public void testConvert_dateAndPartialTime_throwsException() { void testConvert_dateAndPartialTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02")); assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02"));
} }
} }

View file

@ -20,98 +20,96 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link DateTimeParameter}. */ /** Unit tests for {@link DateTimeParameter}. */
@RunWith(JUnit4.class) class DateTimeParameterTest {
public class DateTimeParameterTest {
private final DateTimeParameter instance = new DateTimeParameter(); private final DateTimeParameter instance = new DateTimeParameter();
@Test @Test
public void testConvert_numeric_returnsMillisFromEpochUtc() { void testConvert_numeric_returnsMillisFromEpochUtc() {
assertThat(instance.convert("1234")).isEqualTo(new DateTime(1234L, UTC)); assertThat(instance.convert("1234")).isEqualTo(new DateTime(1234L, UTC));
} }
@Test @Test
public void testConvert_iso8601_returnsSameAsDateTimeParse() { void testConvert_iso8601_returnsSameAsDateTimeParse() {
String exampleDate = "2014-01-01T01:02:03.004Z"; String exampleDate = "2014-01-01T01:02:03.004Z";
assertThat(instance.convert(exampleDate)) assertThat(instance.convert(exampleDate))
.isEqualTo(DateTime.parse(exampleDate)); .isEqualTo(DateTime.parse(exampleDate));
} }
@Test @Test
public void testConvert_isoDateTimeWithMillis_returnsSameAsDateTimeParse() { void testConvert_isoDateTimeWithMillis_returnsSameAsDateTimeParse() {
String exampleDate = "2014-01-01T01:02:03.004Z"; String exampleDate = "2014-01-01T01:02:03.004Z";
assertThat(instance.convert(exampleDate)).isEqualTo(DateTime.parse(exampleDate)); assertThat(instance.convert(exampleDate)).isEqualTo(DateTime.parse(exampleDate));
} }
@Test @Test
public void testConvert_weirdTimezone_convertsToUtc() { void testConvert_weirdTimezone_convertsToUtc() {
assertThat(instance.convert("1984-12-18T00:00:00-0520")) assertThat(instance.convert("1984-12-18T00:00:00-0520"))
.isEqualTo(DateTime.parse("1984-12-18T05:20:00Z")); .isEqualTo(DateTime.parse("1984-12-18T05:20:00Z"));
} }
@Test @Test
public void testConvert_null_throwsException() { void testConvert_null_throwsException() {
assertThrows(NullPointerException.class, () -> instance.convert(null)); assertThrows(NullPointerException.class, () -> instance.convert(null));
} }
@Test @Test
public void testConvert_empty_throwsException() { void testConvert_empty_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("")); assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
} }
@Test @Test
public void testConvert_sillyString_throwsException() { void testConvert_sillyString_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo")); assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
} }
@Test @Test
public void testConvert_partialDate_throwsException() { void testConvert_partialDate_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01")); assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01"));
} }
@Test @Test
public void testConvert_onlyDate_throwsException() { void testConvert_onlyDate_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01")); assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01"));
} }
@Test @Test
public void testConvert_partialTime_throwsException() { void testConvert_partialTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("T01:02")); assertThrows(IllegalArgumentException.class, () -> instance.convert("T01:02"));
} }
@Test @Test
public void testConvert_onlyTime_throwsException() { void testConvert_onlyTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("T01:02:03")); assertThrows(IllegalArgumentException.class, () -> instance.convert("T01:02:03"));
} }
@Test @Test
public void testConvert_partialDateAndPartialTime_throwsException() { void testConvert_partialDateAndPartialTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("9T9")); assertThrows(IllegalArgumentException.class, () -> instance.convert("9T9"));
} }
@Test @Test
public void testConvert_dateAndPartialTime_throwsException() { void testConvert_dateAndPartialTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02")); assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02"));
} }
@Test @Test
public void testConvert_noTimeZone_throwsException() { void testConvert_noTimeZone_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02:03")); assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02:03"));
} }
@Test @Test
public void testValidate_sillyString_throwsParameterException() { void testValidate_sillyString_throwsParameterException() {
ParameterException thrown = ParameterException thrown =
assertThrows(ParameterException.class, () -> instance.validate("--time", "foo")); assertThrows(ParameterException.class, () -> instance.validate("--time", "foo"));
assertThat(thrown).hasMessageThat().contains("--time=foo not an ISO"); assertThat(thrown).hasMessageThat().contains("--time=foo not an ISO");
} }
@Test @Test
public void testValidate_correctInput_doesntThrow() { void testValidate_correctInput_doesntThrow() {
instance.validate("--time", "123"); instance.validate("--time", "123");
} }
} }

View file

@ -20,67 +20,65 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.joda.time.Period; import org.joda.time.Period;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link DurationParameter}. */ /** Unit tests for {@link DurationParameter}. */
@RunWith(JUnit4.class) class DurationParameterTest {
public class DurationParameterTest {
private final DurationParameter instance = new DurationParameter(); private final DurationParameter instance = new DurationParameter();
@Test @Test
public void testConvert_isoHours() { void testConvert_isoHours() {
assertThat(instance.convert("PT36H")).isEqualTo(Duration.standardHours(36)); assertThat(instance.convert("PT36H")).isEqualTo(Duration.standardHours(36));
} }
@Test @Test
public void testConvert_isoDaysAndHours() { void testConvert_isoDaysAndHours() {
assertThat(instance.convert("P1DT12H")).isEqualTo(Duration.standardHours(36)); assertThat(instance.convert("P1DT12H")).isEqualTo(Duration.standardHours(36));
} }
@Test @Test
public void testConvert_isoLowercase_isAllowed() { void testConvert_isoLowercase_isAllowed() {
assertThat(instance.convert("pt36h")).isEqualTo(Duration.standardHours(36)); assertThat(instance.convert("pt36h")).isEqualTo(Duration.standardHours(36));
} }
@Test @Test
public void testIsoMissingP_notAllowed() { void testIsoMissingP_notAllowed() {
assertThrows(IllegalArgumentException.class, () -> Period.parse("T36H")); assertThrows(IllegalArgumentException.class, () -> Period.parse("T36H"));
} }
@Test @Test
public void testIsoMissingPT_notAllowed() { void testIsoMissingPT_notAllowed() {
assertThrows(IllegalArgumentException.class, () -> Period.parse("36H")); assertThrows(IllegalArgumentException.class, () -> Period.parse("36H"));
} }
@Test @Test
public void testConvert_isoMissingP_notAllowed() { void testConvert_isoMissingP_notAllowed() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("T36H")); assertThrows(IllegalArgumentException.class, () -> instance.convert("T36H"));
} }
@Test @Test
public void testConvert_null_throws() { void testConvert_null_throws() {
assertThrows(NullPointerException.class, () -> instance.convert(null)); assertThrows(NullPointerException.class, () -> instance.convert(null));
} }
@Test @Test
public void testConvert_empty_throws() { void testConvert_empty_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("")); assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
} }
@Test @Test
public void testConvert_numeric_throws() { void testConvert_numeric_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("1234")); assertThrows(IllegalArgumentException.class, () -> instance.convert("1234"));
} }
@Test @Test
public void testConvert_sillyString_throws() { void testConvert_sillyString_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo")); assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
} }
@Test @Test
public void testValidate_sillyString_throws() { void testValidate_sillyString_throws() {
ParameterException thrown = ParameterException thrown =
assertThrows(ParameterException.class, () -> instance.validate("--time", "foo")); assertThrows(ParameterException.class, () -> instance.validate("--time", "foo"));
assertThat(thrown).hasMessageThat().contains("--time=foo not an"); assertThat(thrown).hasMessageThat().contains("--time=foo not an");

View file

@ -18,25 +18,22 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows;
import google.registry.model.registry.Registry.TldState; import google.registry.model.registry.Registry.TldState;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link EnumParameter}. */ /** Unit tests for {@link EnumParameter}. */
@RunWith(JUnit4.class) class EnumParameterTest {
public class EnumParameterTest {
// There's no additional functionality exposed by this (or any other) EnumParameter, but using // There's no additional functionality exposed by this (or any other) EnumParameter, but using
// this in the test as EnumParameter is abstract. // this in the test as EnumParameter is abstract.
private final TldStateParameter instance = new TldStateParameter(); private final TldStateParameter instance = new TldStateParameter();
@Test @Test
public void testSuccess_convertEnum() { void testSuccess_convertEnum() {
assertThat(instance.convert("PREDELEGATION")).isEqualTo(TldState.PREDELEGATION); assertThat(instance.convert("PREDELEGATION")).isEqualTo(TldState.PREDELEGATION);
} }
@Test @Test
public void testFailure_badValue() { void testFailure_badValue() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> instance.convert("FREE_DOMAINS")); assertThrows(IllegalArgumentException.class, () -> instance.convert("FREE_DOMAINS"));
assertThat(thrown) assertThat(thrown)

View file

@ -16,36 +16,33 @@ package google.registry.tools.params;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link HostAndPortParameter}. */ /** Unit tests for {@link HostAndPortParameter}. */
@RunWith(JUnit4.class) class HostAndPortParameterTest {
public class HostAndPortParameterTest {
private final HostAndPortParameter instance = new HostAndPortParameter(); private final HostAndPortParameter instance = new HostAndPortParameter();
@Test @Test
public void testConvert_hostOnly() { void testConvert_hostOnly() {
assertThat(instance.convert("foo.bar").getHost()).isEqualTo("foo.bar"); assertThat(instance.convert("foo.bar").getHost()).isEqualTo("foo.bar");
assertThat(instance.convert("foo.bar").getPortOrDefault(31337)).isEqualTo(31337); assertThat(instance.convert("foo.bar").getPortOrDefault(31337)).isEqualTo(31337);
} }
@Test @Test
public void testConvert_hostAndPort() { void testConvert_hostAndPort() {
assertThat(instance.convert("foo.bar:1234").getHost()).isEqualTo("foo.bar"); assertThat(instance.convert("foo.bar:1234").getHost()).isEqualTo("foo.bar");
assertThat(instance.convert("foo.bar:1234").getPortOrDefault(31337)).isEqualTo(1234); assertThat(instance.convert("foo.bar:1234").getPortOrDefault(31337)).isEqualTo(1234);
} }
@Test @Test
public void testConvert_ipv6_hostOnly() { void testConvert_ipv6_hostOnly() {
assertThat(instance.convert("[feed:a:bee]").getHost()).isEqualTo("feed:a:bee"); assertThat(instance.convert("[feed:a:bee]").getHost()).isEqualTo("feed:a:bee");
assertThat(instance.convert("[feed:a:bee]").getPortOrDefault(31337)).isEqualTo(31337); assertThat(instance.convert("[feed:a:bee]").getPortOrDefault(31337)).isEqualTo(31337);
} }
@Test @Test
public void testConvert_ipv6_hostAndPort() { void testConvert_ipv6_hostAndPort() {
assertThat(instance.convert("[feed:a:bee]:1234").getHost()).isEqualTo("feed:a:bee"); assertThat(instance.convert("[feed:a:bee]:1234").getHost()).isEqualTo("feed:a:bee");
assertThat(instance.convert("[feed:a:bee]:1234").getPortOrDefault(31337)).isEqualTo(1234); assertThat(instance.convert("[feed:a:bee]:1234").getPortOrDefault(31337)).isEqualTo(1234);
} }

View file

@ -20,17 +20,15 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.Interval; import org.joda.time.Interval;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link IntervalParameter}. */ /** Unit tests for {@link IntervalParameter}. */
@RunWith(JUnit4.class) class IntervalParameterTest {
public class IntervalParameterTest {
private final IntervalParameter instance = new IntervalParameter(); private final IntervalParameter instance = new IntervalParameter();
@Test @Test
public void testConvert() { void testConvert() {
assertThat(instance.convert("2004-06-09T12:30:00Z/2004-07-10T13:30:00Z")) assertThat(instance.convert("2004-06-09T12:30:00Z/2004-07-10T13:30:00Z"))
.isEqualTo(new Interval( .isEqualTo(new Interval(
DateTime.parse("2004-06-09T12:30:00Z"), DateTime.parse("2004-06-09T12:30:00Z"),
@ -38,34 +36,34 @@ public class IntervalParameterTest {
} }
@Test @Test
public void testConvert_singleDate() { void testConvert_singleDate() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2004-06-09T12:30:00Z")); assertThrows(IllegalArgumentException.class, () -> instance.convert("2004-06-09T12:30:00Z"));
} }
@Test @Test
public void testConvert_backwardsInterval() { void testConvert_backwardsInterval() {
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> instance.convert("2004-07-10T13:30:00Z/2004-06-09T12:30:00Z")); () -> instance.convert("2004-07-10T13:30:00Z/2004-06-09T12:30:00Z"));
} }
@Test @Test
public void testConvert_empty_throws() { void testConvert_empty_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("")); assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
} }
@Test @Test
public void testConvert_null_throws() { void testConvert_null_throws() {
assertThrows(NullPointerException.class, () -> instance.convert(null)); assertThrows(NullPointerException.class, () -> instance.convert(null));
} }
@Test @Test
public void testConvert_sillyString_throws() { void testConvert_sillyString_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo")); assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
} }
@Test @Test
public void testValidate_sillyString_throws() { void testValidate_sillyString_throws() {
ParameterException thrown = ParameterException thrown =
assertThrows(ParameterException.class, () -> instance.validate("--time", "foo")); assertThrows(ParameterException.class, () -> instance.validate("--time", "foo"));
assertThat(thrown).hasMessageThat().contains("--time=foo not an"); assertThat(thrown).hasMessageThat().contains("--time=foo not an");

View file

@ -23,76 +23,74 @@ import google.registry.tools.params.KeyValueMapParameter.StringToIntegerMap;
import google.registry.tools.params.KeyValueMapParameter.StringToStringMap; import google.registry.tools.params.KeyValueMapParameter.StringToStringMap;
import org.joda.money.CurrencyUnit; import org.joda.money.CurrencyUnit;
import org.joda.money.IllegalCurrencyException; import org.joda.money.IllegalCurrencyException;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link KeyValueMapParameter}. */ /** Unit tests for {@link KeyValueMapParameter}. */
@RunWith(JUnit4.class) class KeyValueMapParameterTest {
public class KeyValueMapParameterTest {
private final StringToStringMap stringToStringInstance = new StringToStringMap(); private final StringToStringMap stringToStringInstance = new StringToStringMap();
private final StringToIntegerMap stringToIntegerInstance = new StringToIntegerMap(); private final StringToIntegerMap stringToIntegerInstance = new StringToIntegerMap();
private final CurrencyUnitToStringMap currencyUnitToStringMap = new CurrencyUnitToStringMap(); private final CurrencyUnitToStringMap currencyUnitToStringMap = new CurrencyUnitToStringMap();
@Test @Test
public void testSuccess_convertStringToString_singleEntry() { void testSuccess_convertStringToString_singleEntry() {
assertThat(stringToStringInstance.convert("key=foo")) assertThat(stringToStringInstance.convert("key=foo"))
.isEqualTo(ImmutableMap.of("key", "foo")); .isEqualTo(ImmutableMap.of("key", "foo"));
} }
@Test @Test
public void testSuccess_convertStringToInteger_singleEntry() { void testSuccess_convertStringToInteger_singleEntry() {
assertThat(stringToIntegerInstance.convert("key=1")) assertThat(stringToIntegerInstance.convert("key=1"))
.isEqualTo(ImmutableMap.of("key", 1)); .isEqualTo(ImmutableMap.of("key", 1));
} }
@Test @Test
public void testSuccess_convertCurrencyUnitToString_singleEntry() { void testSuccess_convertCurrencyUnitToString_singleEntry() {
assertThat(currencyUnitToStringMap.convert("USD=123abc")) assertThat(currencyUnitToStringMap.convert("USD=123abc"))
.isEqualTo(ImmutableMap.of(CurrencyUnit.USD, "123abc")); .isEqualTo(ImmutableMap.of(CurrencyUnit.USD, "123abc"));
} }
@Test @Test
public void testSuccess_convertStringToString() { void testSuccess_convertStringToString() {
assertThat(stringToStringInstance.convert("key=foo,key2=bar")) assertThat(stringToStringInstance.convert("key=foo,key2=bar"))
.isEqualTo(ImmutableMap.of("key", "foo", "key2", "bar")); .isEqualTo(ImmutableMap.of("key", "foo", "key2", "bar"));
} }
@Test @Test
public void testSuccess_convertStringToInteger() { void testSuccess_convertStringToInteger() {
assertThat(stringToIntegerInstance.convert("key=1,key2=2")) assertThat(stringToIntegerInstance.convert("key=1,key2=2"))
.isEqualTo(ImmutableMap.of("key", 1, "key2", 2)); .isEqualTo(ImmutableMap.of("key", 1, "key2", 2));
} }
@Test @Test
public void testSuccess_convertCurrencyUnitToString() { void testSuccess_convertCurrencyUnitToString() {
assertThat(currencyUnitToStringMap.convert("USD=123abc,JPY=xyz789")) assertThat(currencyUnitToStringMap.convert("USD=123abc,JPY=xyz789"))
.isEqualTo(ImmutableMap.of(CurrencyUnit.USD, "123abc", CurrencyUnit.JPY, "xyz789")); .isEqualTo(ImmutableMap.of(CurrencyUnit.USD, "123abc", CurrencyUnit.JPY, "xyz789"));
} }
@Test @Test
public void testSuccess_convertStringToString_empty() { void testSuccess_convertStringToString_empty() {
assertThat(stringToStringInstance.convert("")).isEmpty(); assertThat(stringToStringInstance.convert("")).isEmpty();
} }
@Test @Test
public void testSuccess_convertStringToInteger_empty() { void testSuccess_convertStringToInteger_empty() {
assertThat(stringToIntegerInstance.convert("")).isEmpty(); assertThat(stringToIntegerInstance.convert("")).isEmpty();
} }
@Test @Test
public void testSuccess_convertCurrencyUnitToString_empty() { void testSuccess_convertCurrencyUnitToString_empty() {
assertThat(currencyUnitToStringMap.convert("")).isEmpty(); assertThat(currencyUnitToStringMap.convert("")).isEmpty();
} }
@Test @Test
public void testFailure_convertStringToInteger_badType() { void testFailure_convertStringToInteger_badType() {
assertThrows( assertThrows(
NumberFormatException.class, () -> stringToIntegerInstance.convert("key=1,key2=foo")); NumberFormatException.class, () -> stringToIntegerInstance.convert("key=1,key2=foo"));
} }
@Test @Test
public void testFailure_convertCurrencyUnitToString_badType() { void testFailure_convertCurrencyUnitToString_badType() {
IllegalCurrencyException thrown = IllegalCurrencyException thrown =
assertThrows( assertThrows(
IllegalCurrencyException.class, IllegalCurrencyException.class,
@ -101,36 +99,36 @@ public class KeyValueMapParameterTest {
} }
@Test @Test
public void testFailure_convertStringToString_badSeparator() { void testFailure_convertStringToString_badSeparator() {
assertThrows( assertThrows(
IllegalArgumentException.class, () -> stringToStringInstance.convert("key=foo&key2=bar")); IllegalArgumentException.class, () -> stringToStringInstance.convert("key=foo&key2=bar"));
} }
@Test @Test
public void testFailure_convertStringToInteger_badSeparator() { void testFailure_convertStringToInteger_badSeparator() {
assertThrows( assertThrows(
IllegalArgumentException.class, () -> stringToIntegerInstance.convert("key=1&key2=2")); IllegalArgumentException.class, () -> stringToIntegerInstance.convert("key=1&key2=2"));
} }
@Test @Test
public void testFailure_convertCurrencyUnitToString_badSeparator() { void testFailure_convertCurrencyUnitToString_badSeparator() {
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> currencyUnitToStringMap.convert("USD=123abc&JPY=xyz789")); () -> currencyUnitToStringMap.convert("USD=123abc&JPY=xyz789"));
} }
@Test @Test
public void testFailure_convertStringToString_badFormat() { void testFailure_convertStringToString_badFormat() {
assertThrows(IllegalArgumentException.class, () -> stringToStringInstance.convert("foo")); assertThrows(IllegalArgumentException.class, () -> stringToStringInstance.convert("foo"));
} }
@Test @Test
public void testFailure_convertStringToInteger_badFormat() { void testFailure_convertStringToInteger_badFormat() {
assertThrows(IllegalArgumentException.class, () -> stringToIntegerInstance.convert("foo")); assertThrows(IllegalArgumentException.class, () -> stringToIntegerInstance.convert("foo"));
} }
@Test @Test
public void testFailure_convertCurrencyUnitToString_badFormat() { void testFailure_convertCurrencyUnitToString_badFormat() {
assertThrows(IllegalArgumentException.class, () -> currencyUnitToStringMap.convert("foo")); assertThrows(IllegalArgumentException.class, () -> currencyUnitToStringMap.convert("foo"));
} }
} }

View file

@ -19,64 +19,62 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.joda.money.Money; import org.joda.money.Money;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link MoneyParameter}. */ /** Unit tests for {@link MoneyParameter}. */
@RunWith(JUnit4.class) class MoneyParameterTest {
public class MoneyParameterTest {
private final MoneyParameter instance = new MoneyParameter(); private final MoneyParameter instance = new MoneyParameter();
@Test @Test
public void testConvert_withCurrency() { void testConvert_withCurrency() {
assertThat(instance.convert("USD 777.99")).isEqualTo(Money.parse("USD 777.99")); assertThat(instance.convert("USD 777.99")).isEqualTo(Money.parse("USD 777.99"));
} }
@Test @Test
public void testConvert_negative() { void testConvert_negative() {
assertThat(instance.convert("USD -777.99")).isEqualTo(Money.parse("USD -777.99")); assertThat(instance.convert("USD -777.99")).isEqualTo(Money.parse("USD -777.99"));
} }
@Test @Test
public void testConvert_missingSpace_isForgiving() { void testConvert_missingSpace_isForgiving() {
assertThat(instance.convert("USD777.99")).isEqualTo(Money.parse("USD 777.99")); assertThat(instance.convert("USD777.99")).isEqualTo(Money.parse("USD 777.99"));
} }
@Test @Test
public void testConvert_lowercase_isForgiving() { void testConvert_lowercase_isForgiving() {
assertThat(instance.convert("usd777.99")).isEqualTo(Money.parse("USD 777.99")); assertThat(instance.convert("usd777.99")).isEqualTo(Money.parse("USD 777.99"));
} }
@Test @Test
public void testConvert_badCurrency_throws() { void testConvert_badCurrency_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("FOO 1337")); assertThrows(IllegalArgumentException.class, () -> instance.convert("FOO 1337"));
} }
@Test @Test
public void testConvert_null_throws() { void testConvert_null_throws() {
assertThrows(NullPointerException.class, () -> instance.convert(null)); assertThrows(NullPointerException.class, () -> instance.convert(null));
} }
@Test @Test
public void testConvert_empty_throws() { void testConvert_empty_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("")); assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
} }
@Test @Test
public void testConvert_sillyString_throws() { void testConvert_sillyString_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo")); assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
} }
@Test @Test
public void testValidate_sillyString_throws() { void testValidate_sillyString_throws() {
ParameterException thrown = ParameterException thrown =
assertThrows(ParameterException.class, () -> instance.validate("--money", "foo")); assertThrows(ParameterException.class, () -> instance.validate("--money", "foo"));
assertThat(thrown).hasMessageThat().contains("--money=foo not valid"); assertThat(thrown).hasMessageThat().contains("--money=foo not valid");
} }
@Test @Test
public void testValidate_correctInput() { void testValidate_correctInput() {
instance.validate("--money", "USD 777"); instance.validate("--money", "USD 777");
} }
} }

View file

@ -20,42 +20,39 @@ import static google.registry.tools.params.NameserversParameter.splitNameservers
import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link NameserversParameter}. */ /** Unit tests for {@link NameserversParameter}. */
@RunWith(JUnit4.class) class NameserversParameterTest {
public class NameserversParameterTest {
private final NameserversParameter instance = new NameserversParameter(); private final NameserversParameter instance = new NameserversParameter();
@Test @Test
public void testConvert_singleBasicNameserver() { void testConvert_singleBasicNameserver() {
assertThat(instance.convert("ns11.goes.to")).containsExactly("ns11.goes.to"); assertThat(instance.convert("ns11.goes.to")).containsExactly("ns11.goes.to");
} }
@Test @Test
public void testConvert_multipleBasicNameservers() { void testConvert_multipleBasicNameservers() {
assertThat(instance.convert("ns1.tim.buktu, ns2.tim.buktu, ns3.tim.buktu")) assertThat(instance.convert("ns1.tim.buktu, ns2.tim.buktu, ns3.tim.buktu"))
.containsExactly("ns1.tim.buktu", "ns2.tim.buktu", "ns3.tim.buktu"); .containsExactly("ns1.tim.buktu", "ns2.tim.buktu", "ns3.tim.buktu");
} }
@Test @Test
public void testConvert_kitchenSink() { void testConvert_kitchenSink() {
assertThat(instance.convert(" ns1.foo.bar, ,ns2.foo.bar,, ns[1-3].range.baz ")) assertThat(instance.convert(" ns1.foo.bar, ,ns2.foo.bar,, ns[1-3].range.baz "))
.containsExactly( .containsExactly(
"ns1.foo.bar", "ns2.foo.bar", "ns1.range.baz", "ns2.range.baz", "ns3.range.baz"); "ns1.foo.bar", "ns2.foo.bar", "ns1.range.baz", "ns2.range.baz", "ns3.range.baz");
} }
@Test @Test
public void testConvert_invalid() { void testConvert_invalid() {
assertThat(instance.convert("ns1.foo.bar,ns2.foo.baz,ns3.foo.bar")) assertThat(instance.convert("ns1.foo.bar,ns2.foo.baz,ns3.foo.bar"))
.containsExactly("ns1.foo.bar", "ns3.foo.bar", "ns2.foo.baz"); .containsExactly("ns1.foo.bar", "ns3.foo.bar", "ns2.foo.baz");
} }
@Test @Test
public void testValidate_sillyString_throws() { void testValidate_sillyString_throws() {
ParameterException thrown = ParameterException thrown =
assertThrows(ParameterException.class, () -> instance.validate("nameservers", "[[ns]]")); assertThrows(ParameterException.class, () -> instance.validate("nameservers", "[[ns]]"));
assertThat(thrown).hasMessageThat().contains("Must be a comma-delimited list of nameservers"); assertThat(thrown).hasMessageThat().contains("Must be a comma-delimited list of nameservers");
@ -63,40 +60,40 @@ public class NameserversParameterTest {
} }
@Test @Test
public void testConvert_empty_returnsEmpty() { void testConvert_empty_returnsEmpty() {
assertThat(instance.convert("")).isEmpty(); assertThat(instance.convert("")).isEmpty();
} }
@Test @Test
public void testConvert_nullString_returnsNull() { void testConvert_nullString_returnsNull() {
assertThat(instance.convert(null)).isEmpty(); assertThat(instance.convert(null)).isEmpty();
} }
@Test @Test
public void testSplitNameservers_noopWithNoBrackets() { void testSplitNameservers_noopWithNoBrackets() {
assertThat(splitNameservers("ns9.fake.example")).containsExactly("ns9.fake.example"); assertThat(splitNameservers("ns9.fake.example")).containsExactly("ns9.fake.example");
} }
@Test @Test
public void testSplitNameservers_worksWithBrackets() { void testSplitNameservers_worksWithBrackets() {
assertThat(splitNameservers("ns[1-4].zan.zibar")) assertThat(splitNameservers("ns[1-4].zan.zibar"))
.containsExactly("ns1.zan.zibar", "ns2.zan.zibar", "ns3.zan.zibar", "ns4.zan.zibar"); .containsExactly("ns1.zan.zibar", "ns2.zan.zibar", "ns3.zan.zibar", "ns4.zan.zibar");
} }
@Test @Test
public void testSplitNameservers_worksWithBrackets_soloRange() { void testSplitNameservers_worksWithBrackets_soloRange() {
assertThat(splitNameservers("ns[1-1].zan.zibar")).containsExactly("ns1.zan.zibar"); assertThat(splitNameservers("ns[1-1].zan.zibar")).containsExactly("ns1.zan.zibar");
} }
@Test @Test
public void testSplitNameservers_throwsOnInvalidRange() { void testSplitNameservers_throwsOnInvalidRange() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> splitNameservers("ns[9-2].foo.bar")); assertThrows(IllegalArgumentException.class, () -> splitNameservers("ns[9-2].foo.bar"));
assertThat(thrown).hasMessageThat().isEqualTo("Number range [9-2] is invalid"); assertThat(thrown).hasMessageThat().isEqualTo("Number range [9-2] is invalid");
} }
@Test @Test
public void testSplitNameservers_throwsOnInvalidHostname_missingPrefix() { void testSplitNameservers_throwsOnInvalidHostname_missingPrefix() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> splitNameservers("[1-4].foo.bar")); assertThrows(IllegalArgumentException.class, () -> splitNameservers("[1-4].foo.bar"));
assertThat(thrown) assertThat(thrown)
@ -105,7 +102,7 @@ public class NameserversParameterTest {
} }
@Test @Test
public void testSplitNameservers_throwsOnInvalidHostname_missingDomainName() { void testSplitNameservers_throwsOnInvalidHostname_missingDomainName() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> splitNameservers("this.is.ns[1-5]")); assertThrows(IllegalArgumentException.class, () -> splitNameservers("this.is.ns[1-5]"));
assertThat(thrown) assertThat(thrown)
@ -114,7 +111,7 @@ public class NameserversParameterTest {
} }
@Test @Test
public void testSplitNameservers_throwsOnInvalidRangeSyntax() { void testSplitNameservers_throwsOnInvalidRangeSyntax() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> splitNameservers("ns[1-4[.foo.bar")); assertThrows(IllegalArgumentException.class, () -> splitNameservers("ns[1-4[.foo.bar"));
assertThat(thrown).hasMessageThat().contains("Could not parse square brackets"); assertThat(thrown).hasMessageThat().contains("Could not parse square brackets");

View file

@ -30,41 +30,37 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermissions; import java.nio.file.attribute.PosixFilePermissions;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.io.TempDir;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link PathParameter}. */ /** Unit tests for {@link PathParameter}. */
@RunWith(JUnit4.class) class PathParameterTest {
public class PathParameterTest {
@Rule @TempDir Path tmpDir;
public final TemporaryFolder folder = new TemporaryFolder();
// ================================ Test Convert ============================================== // ================================ Test Convert ==============================================
private final PathParameter vanilla = new PathParameter(); private final PathParameter vanilla = new PathParameter();
@Test @Test
public void testConvert_etcPasswd_returnsPath() { void testConvert_etcPasswd_returnsPath() {
assertThat((Object) vanilla.convert("/etc/passwd")).isEqualTo(Paths.get("/etc/passwd")); assertThat((Object) vanilla.convert("/etc/passwd")).isEqualTo(Paths.get("/etc/passwd"));
} }
@Test @Test
public void testConvert_null_throws() { void testConvert_null_throws() {
assertThrows(NullPointerException.class, () -> vanilla.convert(null)); assertThrows(NullPointerException.class, () -> vanilla.convert(null));
} }
@Test @Test
public void testConvert_empty_throws() { void testConvert_empty_throws() {
assertThrows(IllegalArgumentException.class, () -> vanilla.convert("")); assertThrows(IllegalArgumentException.class, () -> vanilla.convert(""));
} }
@Test @Test
public void testConvert_relativePath_returnsOriginalFile() throws Exception { void testConvert_relativePath_returnsOriginalFile() throws Exception {
Path currentDirectory = Paths.get("").toAbsolutePath(); Path currentDirectory = Paths.get("").toAbsolutePath();
Path file = Paths.get(folder.newFile().toString()); Path file = Paths.get(tmpDir.resolve("tmp.file").toString());
Path relative = file.relativize(currentDirectory); Path relative = file.relativize(currentDirectory);
assumeThat(relative, is(not(equalTo(file)))); assumeThat(relative, is(not(equalTo(file))));
assumeThat(relative.toString(), startsWith("../")); assumeThat(relative.toString(), startsWith("../"));
@ -73,13 +69,13 @@ public class PathParameterTest {
} }
@Test @Test
public void testConvert_extraSlash_returnsWithoutSlash() throws Exception { void testConvert_extraSlash_returnsWithoutSlash() throws Exception {
Path file = Paths.get(folder.newFile().toString()); Path file = Paths.get(tmpDir.resolve("file.new").toString());
assertThat((Object) vanilla.convert(file + "/")).isEqualTo(file); assertThat((Object) vanilla.convert(file + "/")).isEqualTo(file);
} }
@Test @Test
public void testConvert_uriNotProvided() { void testConvert_uriNotProvided() {
assertThrows(FileSystemNotFoundException.class, () -> vanilla.convert("bog://bucket/lolcat")); assertThrows(FileSystemNotFoundException.class, () -> vanilla.convert("bog://bucket/lolcat"));
} }
@ -88,31 +84,30 @@ public class PathParameterTest {
private final PathParameter inputFile = new PathParameter.InputFile(); private final PathParameter inputFile = new PathParameter.InputFile();
@Test @Test
public void testInputFileValidate_normalFile_works() throws Exception { void testInputFileValidate_normalFile_works() throws Exception {
inputFile.validate("input", folder.newFile().toString()); inputFile.validate("input", Files.createFile(tmpDir.resolve("tmpfile.txt")).toString());
} }
@Test @Test
public void testInputFileValidate_missingFile_throws() { void testInputFileValidate_missingFile_throws() {
ParameterException thrown = ParameterException thrown =
assertThrows( assertThrows(
ParameterException.class, ParameterException.class,
() -> inputFile.validate("input", new File(folder.getRoot(), "foo").toString())); () -> inputFile.validate("input", tmpDir.resolve("foo").toString()));
assertThat(thrown).hasMessageThat().contains("not found"); assertThat(thrown).hasMessageThat().contains("not found");
} }
@Test @Test
public void testInputFileValidate_directory_throws() { void testInputFileValidate_directory_throws() {
ParameterException thrown = ParameterException thrown =
assertThrows( assertThrows(
ParameterException.class, ParameterException.class, () -> inputFile.validate("input", tmpDir.toString()));
() -> inputFile.validate("input", folder.getRoot().toString()));
assertThat(thrown).hasMessageThat().contains("is a directory"); assertThat(thrown).hasMessageThat().contains("is a directory");
} }
@Test @Test
public void testInputFileValidate_unreadableFile_throws() throws Exception { void testInputFileValidate_unreadableFile_throws() throws Exception {
Path file = Paths.get(folder.newFile().toString()); Path file = Files.createFile(tmpDir.resolve("tmpfile.txt"));
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("-w-------")); Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("-w-------"));
ParameterException thrown = ParameterException thrown =
assertThrows(ParameterException.class, () -> inputFile.validate("input", file.toString())); assertThrows(ParameterException.class, () -> inputFile.validate("input", file.toString()));
@ -124,33 +119,32 @@ public class PathParameterTest {
private final PathParameter outputFile = new PathParameter.OutputFile(); private final PathParameter outputFile = new PathParameter.OutputFile();
@Test @Test
public void testOutputFileValidate_normalFile_works() throws Exception { void testOutputFileValidate_normalFile_works() throws Exception {
outputFile.validate("input", folder.newFile().toString()); outputFile.validate("input", tmpDir.resolve("testfile").toString());
} }
@Test @Test
public void testInputFileValidate_characterDeviceBehindSymbolicLinks_works() { void testInputFileValidate_characterDeviceBehindSymbolicLinks_works() {
assumeTrue(Files.exists(Paths.get("/dev/stdin"))); assumeTrue(Files.exists(Paths.get("/dev/stdin")));
outputFile.validate("input", "/dev/stdin"); outputFile.validate("input", "/dev/stdin");
} }
@Test @Test
public void testOutputFileValidate_missingFile_works() { void testOutputFileValidate_missingFile_works() {
outputFile.validate("input", new File(folder.getRoot(), "foo").toString()); outputFile.validate("input", new File(tmpDir.toFile(), "foo").toString());
} }
@Test @Test
public void testOutputFileValidate_directory_throws() { void testOutputFileValidate_directory_throws() {
ParameterException thrown = ParameterException thrown =
assertThrows( assertThrows(
ParameterException.class, ParameterException.class, () -> outputFile.validate("input", tmpDir.toString()));
() -> outputFile.validate("input", folder.getRoot().toString()));
assertThat(thrown).hasMessageThat().contains("is a directory"); assertThat(thrown).hasMessageThat().contains("is a directory");
} }
@Test @Test
public void testOutputFileValidate_notWritable_throws() throws Exception { void testOutputFileValidate_notWritable_throws() throws Exception {
Path file = Paths.get(folder.newFile().toString()); Path file = Files.createFile(tmpDir.resolve("newFile.dat"));
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("r--------")); Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("r--------"));
ParameterException thrown = ParameterException thrown =
assertThrows(ParameterException.class, () -> outputFile.validate("input", file.toString())); assertThrows(ParameterException.class, () -> outputFile.validate("input", file.toString()));
@ -158,16 +152,16 @@ public class PathParameterTest {
} }
@Test @Test
public void testOutputFileValidate_parentDirMissing_throws() { void testOutputFileValidate_parentDirMissing_throws() {
Path file = Paths.get(folder.getRoot().toString(), "MISSINGNO", "foo.txt"); Path file = Paths.get(tmpDir.toString(), "MISSINGNO", "foo.txt");
ParameterException thrown = ParameterException thrown =
assertThrows(ParameterException.class, () -> outputFile.validate("input", file.toString())); assertThrows(ParameterException.class, () -> outputFile.validate("input", file.toString()));
assertThat(thrown).hasMessageThat().contains("parent dir doesn't exist"); assertThat(thrown).hasMessageThat().contains("parent dir doesn't exist");
} }
@Test @Test
public void testOutputFileValidate_parentDirIsFile_throws() throws Exception { void testOutputFileValidate_parentDirIsFile_throws() throws Exception {
Path file = Paths.get(folder.newFile().toString(), "foo.txt"); Path file = Paths.get(Files.createFile(tmpDir.resolve("foo.file")).toString(), "foo.txt");
ParameterException thrown = ParameterException thrown =
assertThrows(ParameterException.class, () -> outputFile.validate("input", file.toString())); assertThrows(ParameterException.class, () -> outputFile.validate("input", file.toString()));
assertThat(thrown).hasMessageThat().contains("parent is non-directory"); assertThat(thrown).hasMessageThat().contains("parent is non-directory");

View file

@ -17,32 +17,30 @@ package google.registry.tools.params;
import static com.google.common.truth.Truth8.assertThat; import static com.google.common.truth.Truth8.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link PhoneNumberParameter}. */ /** Unit tests for {@link PhoneNumberParameter}. */
@RunWith(JUnit4.class) class PhoneNumberParameterTest {
public class PhoneNumberParameterTest {
private final OptionalPhoneNumberParameter instance = new OptionalPhoneNumberParameter(); private final OptionalPhoneNumberParameter instance = new OptionalPhoneNumberParameter();
@Test @Test
public void testConvert_e164() { void testConvert_e164() {
assertThat(instance.convert("+1.2125550777")).hasValue("+1.2125550777"); assertThat(instance.convert("+1.2125550777")).hasValue("+1.2125550777");
} }
@Test @Test
public void testConvert_sillyString_throws() { void testConvert_sillyString_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo")); assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
} }
@Test @Test
public void testConvert_empty_returnsEmpty() { void testConvert_empty_returnsEmpty() {
assertThat(instance.convert("")).isEmpty(); assertThat(instance.convert("")).isEmpty();
} }
@Test @Test
public void testConvert_nullString_returnsEmpty() { void testConvert_nullString_returnsEmpty() {
assertThat(instance.convert("null")).isEmpty(); assertThat(instance.convert("null")).isEmpty();
} }
} }

View file

@ -19,54 +19,52 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.joda.time.YearMonth; import org.joda.time.YearMonth;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link YearMonthParameter}. */ /** Unit tests for {@link YearMonthParameter}. */
@RunWith(JUnit4.class) class YearMonthParameterTest {
public class YearMonthParameterTest {
private final YearMonthParameter instance = new YearMonthParameter(); private final YearMonthParameter instance = new YearMonthParameter();
@Test @Test
public void testConvert_awfulMonth() { void testConvert_awfulMonth() {
assertThat(instance.convert("1984-12")).isEqualTo(new YearMonth(1984, 12)); assertThat(instance.convert("1984-12")).isEqualTo(new YearMonth(1984, 12));
} }
@Test @Test
public void testConvert_null_throwsException() { void testConvert_null_throwsException() {
assertThrows(NullPointerException.class, () -> instance.convert(null)); assertThrows(NullPointerException.class, () -> instance.convert(null));
} }
@Test @Test
public void testConvert_empty_throwsException() { void testConvert_empty_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("")); assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
} }
@Test @Test
public void testConvert_sillyString_throwsException() { void testConvert_sillyString_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo")); assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
} }
@Test @Test
public void testConvert_wrongOrder() { void testConvert_wrongOrder() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("12-1984")); assertThrows(IllegalArgumentException.class, () -> instance.convert("12-1984"));
} }
@Test @Test
public void testConvert_noHyphen() { void testConvert_noHyphen() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("198412")); assertThrows(IllegalArgumentException.class, () -> instance.convert("198412"));
} }
@Test @Test
public void testValidate_sillyString_throwsParameterException() { void testValidate_sillyString_throwsParameterException() {
ParameterException thrown = ParameterException thrown =
assertThrows(ParameterException.class, () -> instance.validate("--time", "foo")); assertThrows(ParameterException.class, () -> instance.validate("--time", "foo"));
assertThat(thrown).hasMessageThat().contains("--time=foo not a valid"); assertThat(thrown).hasMessageThat().contains("--time=foo not a valid");
} }
@Test @Test
public void testValidate_correctInput_doesntThrow() { void testValidate_correctInput_doesntThrow() {
instance.validate("--time", "1984-12"); instance.validate("--time", "1984-12");
} }
} }

View file

@ -30,22 +30,16 @@ import google.registry.request.Response;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import google.registry.testing.InjectRule; import google.registry.testing.InjectRule;
import java.util.Optional; import java.util.Optional;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** /** Unit tests for {@link CreateGroupsAction}. */
* Unit tests for {@link CreateGroupsAction}. class CreateGroupsActionTest {
*/
@RunWith(JUnit4.class)
public class CreateGroupsActionTest {
@Rule @RegisterExtension
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Rule @RegisterExtension final InjectRule inject = new InjectRule();
public final InjectRule inject = new InjectRule();
private final DirectoryGroupsConnection connection = mock(DirectoryGroupsConnection.class); private final DirectoryGroupsConnection connection = mock(DirectoryGroupsConnection.class);
private final Response response = mock(Response.class); private final Response response = mock(Response.class);
@ -60,7 +54,7 @@ public class CreateGroupsActionTest {
} }
@Test @Test
public void test_invalidRequest_missingClientId() { void test_invalidRequest_missingClientId() {
BadRequestException thrown = assertThrows(BadRequestException.class, () -> runAction(null)); BadRequestException thrown = assertThrows(BadRequestException.class, () -> runAction(null));
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
@ -68,7 +62,7 @@ public class CreateGroupsActionTest {
} }
@Test @Test
public void test_invalidRequest_invalidClientId() { void test_invalidRequest_invalidClientId() {
BadRequestException thrown = BadRequestException thrown =
assertThrows(BadRequestException.class, () -> runAction("completelyMadeUpClientId")); assertThrows(BadRequestException.class, () -> runAction("completelyMadeUpClientId"));
assertThat(thrown) assertThat(thrown)
@ -79,7 +73,7 @@ public class CreateGroupsActionTest {
} }
@Test @Test
public void test_createsAllGroupsSuccessfully() throws Exception { void test_createsAllGroupsSuccessfully() throws Exception {
runAction("NewRegistrar"); runAction("NewRegistrar");
verify(response).setStatus(SC_OK); verify(response).setStatus(SC_OK);
verify(response).setPayload("Success!"); verify(response).setPayload("Success!");
@ -90,7 +84,7 @@ public class CreateGroupsActionTest {
} }
@Test @Test
public void test_createsSomeGroupsSuccessfully_whenOthersFail() throws Exception { void test_createsSomeGroupsSuccessfully_whenOthersFail() throws Exception {
when(connection.createGroup("newregistrar-primary-contacts@domain-registry.example")) when(connection.createGroup("newregistrar-primary-contacts@domain-registry.example"))
.thenThrow(new RuntimeException("Could not contact server.")); .thenThrow(new RuntimeException("Could not contact server."));
doThrow(new RuntimeException("Invalid access.")).when(connection).addMemberToGroup( doThrow(new RuntimeException("Invalid access.")).when(connection).addMemberToGroup(

View file

@ -27,26 +27,23 @@ import google.registry.model.registry.label.PremiumList;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeJsonResponse; import google.registry.testing.FakeJsonResponse;
import org.joda.money.Money; import org.joda.money.Money;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** /**
* Unit tests for {@link CreatePremiumListAction}. * Unit tests for {@link CreatePremiumListAction}.
*/ */
@RunWith(JUnit4.class)
public class CreatePremiumListActionTest { public class CreatePremiumListActionTest {
@Rule @RegisterExtension
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
CreatePremiumListAction action; private CreatePremiumListAction action;
FakeJsonResponse response; private FakeJsonResponse response;
@Before @BeforeEach
public void init() { void beforeEach() {
createTlds("foo", "xn--q9jyb4c", "how"); createTlds("foo", "xn--q9jyb4c", "how");
deletePremiumList(PremiumList.getUncached("foo").get()); deletePremiumList(PremiumList.getUncached("foo").get());
action = new CreatePremiumListAction(); action = new CreatePremiumListAction();
@ -55,14 +52,14 @@ public class CreatePremiumListActionTest {
} }
@Test @Test
public void test_invalidRequest_missingInput_returnsErrorStatus() { void test_invalidRequest_missingInput_returnsErrorStatus() {
action.name = "foo"; action.name = "foo";
action.run(); action.run();
assertThat(response.getResponseMap().get("status")).isEqualTo("error"); assertThat(response.getResponseMap().get("status")).isEqualTo("error");
} }
@Test @Test
public void test_invalidRequest_listAlreadyExists_returnsErrorStatus() { void test_invalidRequest_listAlreadyExists_returnsErrorStatus() {
action.name = "how"; action.name = "how";
action.inputData = "richer,JPY 5000"; action.inputData = "richer,JPY 5000";
action.run(); action.run();
@ -74,7 +71,7 @@ public class CreatePremiumListActionTest {
} }
@Test @Test
public void test_nonExistentTld_successWithOverride() { void test_nonExistentTld_successWithOverride() {
action.name = "zanzibar"; action.name = "zanzibar";
action.inputData = "zanzibar,USD 100"; action.inputData = "zanzibar,USD 100";
action.override = true; action.override = true;
@ -84,7 +81,7 @@ public class CreatePremiumListActionTest {
} }
@Test @Test
public void test_success() { void test_success() {
action.name = "foo"; action.name = "foo";
action.inputData = "rich,USD 25\nricher,USD 1000\n"; action.inputData = "rich,USD 25\nricher,USD 1000\n";
action.run(); action.run();

View file

@ -26,22 +26,19 @@ import google.registry.model.registry.label.ReservedList;
import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.BadRequestException;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeResponse; import google.registry.testing.FakeResponse;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link DeleteEntityAction}. */ /** Unit tests for {@link DeleteEntityAction}. */
@RunWith(JUnit4.class) class DeleteEntityActionTest {
public class DeleteEntityActionTest {
@Rule @RegisterExtension
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
FakeResponse response = new FakeResponse(); private FakeResponse response = new FakeResponse();
@Test @Test
public void test_deleteSingleRawEntitySuccessfully() { void test_deleteSingleRawEntitySuccessfully() {
Entity entity = new Entity("single", "raw"); Entity entity = new Entity("single", "raw");
getDatastoreService().put(entity); getDatastoreService().put(entity);
new DeleteEntityAction(KeyFactory.keyToString(entity.getKey()), response).run(); new DeleteEntityAction(KeyFactory.keyToString(entity.getKey()), response).run();
@ -49,7 +46,7 @@ public class DeleteEntityActionTest {
} }
@Test @Test
public void test_deleteSingleRegisteredEntitySuccessfully() { void test_deleteSingleRegisteredEntitySuccessfully() {
ReservedList ofyEntity = new ReservedList.Builder().setName("foo").build(); ReservedList ofyEntity = new ReservedList.Builder().setName("foo").build();
ofy().saveWithoutBackup().entity(ofyEntity).now(); ofy().saveWithoutBackup().entity(ofyEntity).now();
new DeleteEntityAction(KeyFactory.keyToString(create(ofyEntity).getRaw()), response).run(); new DeleteEntityAction(KeyFactory.keyToString(create(ofyEntity).getRaw()), response).run();
@ -57,7 +54,7 @@ public class DeleteEntityActionTest {
} }
@Test @Test
public void test_deletePolymorphicEntity_fallbackSucceedsForUnregisteredType() { void test_deletePolymorphicEntity_fallbackSucceedsForUnregisteredType() {
Entity entity = new Entity("single", "raw"); Entity entity = new Entity("single", "raw");
entity.setIndexedProperty("^d", "UnregType"); entity.setIndexedProperty("^d", "UnregType");
getDatastoreService().put(entity); getDatastoreService().put(entity);
@ -66,7 +63,7 @@ public class DeleteEntityActionTest {
} }
@Test @Test
public void test_deleteOneRawEntityAndOneRegisteredEntitySuccessfully() { void test_deleteOneRawEntityAndOneRegisteredEntitySuccessfully() {
Entity entity = new Entity("first", "raw"); Entity entity = new Entity("first", "raw");
getDatastoreService().put(entity); getDatastoreService().put(entity);
String rawKey = KeyFactory.keyToString(entity.getKey()); String rawKey = KeyFactory.keyToString(entity.getKey());
@ -78,7 +75,7 @@ public class DeleteEntityActionTest {
} }
@Test @Test
public void test_deleteNonExistentEntityRepliesWithError() { void test_deleteNonExistentEntityRepliesWithError() {
Entity entity = new Entity("not", "here"); Entity entity = new Entity("not", "here");
String rawKey = KeyFactory.keyToString(entity.getKey()); String rawKey = KeyFactory.keyToString(entity.getKey());
BadRequestException thrown = BadRequestException thrown =
@ -88,7 +85,7 @@ public class DeleteEntityActionTest {
} }
@Test @Test
public void test_deleteOneEntityAndNonExistentEntityRepliesWithError() { void test_deleteOneEntityAndNonExistentEntityRepliesWithError() {
ReservedList ofyEntity = new ReservedList.Builder().setName("first_registered").build(); ReservedList ofyEntity = new ReservedList.Builder().setName("first_registered").build();
ofy().saveWithoutBackup().entity(ofyEntity).now(); ofy().saveWithoutBackup().entity(ofyEntity).now();
String ofyKey = KeyFactory.keyToString(create(ofyEntity).getRaw()); String ofyKey = KeyFactory.keyToString(create(ofyEntity).getRaw());

View file

@ -22,14 +22,14 @@ import google.registry.testing.FakeJsonResponse;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.junit.Rule; import org.junit.jupiter.api.extension.RegisterExtension;
/** /**
* Base class for tests of list actions. * Base class for tests of list actions.
*/ */
public class ListActionTestCase { public class ListActionTestCase {
@Rule @RegisterExtension
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private FakeJsonResponse response; private FakeJsonResponse response;

View file

@ -22,19 +22,16 @@ import com.google.common.collect.ImmutableSet;
import google.registry.testing.FakeClock; import google.registry.testing.FakeClock;
import java.util.Optional; import java.util.Optional;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link ListDomainsAction}. */ /** Unit tests for {@link ListDomainsAction}. */
@RunWith(JUnit4.class) class ListDomainsActionTest extends ListActionTestCase {
public class ListDomainsActionTest extends ListActionTestCase {
private ListDomainsAction action; private ListDomainsAction action;
@Before @BeforeEach
public void init() { void beforeEach() {
createTld("foo"); createTld("foo");
action = new ListDomainsAction(); action = new ListDomainsAction();
action.clock = new FakeClock(DateTime.parse("2018-01-01TZ")); action.clock = new FakeClock(DateTime.parse("2018-01-01TZ"));
@ -42,7 +39,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_invalidRequest_missingTlds() { void testRun_invalidRequest_missingTlds() {
action.tlds = ImmutableSet.of(); action.tlds = ImmutableSet.of();
testRunError( testRunError(
action, action,
@ -53,7 +50,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_invalidRequest_invalidTld() { void testRun_invalidRequest_invalidTld() {
action.tlds = ImmutableSet.of("%%%badtld%%%"); action.tlds = ImmutableSet.of("%%%badtld%%%");
testRunError( testRunError(
action, action,
@ -64,13 +61,13 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_noParameters() { void testRun_noParameters() {
action.tlds = ImmutableSet.of("foo"); action.tlds = ImmutableSet.of("foo");
testRunSuccess(action, null, null, null); testRunSuccess(action, null, null, null);
} }
@Test @Test
public void testRun_twoLinesWithIdOnly() { void testRun_twoLinesWithIdOnly() {
action.tlds = ImmutableSet.of("foo"); action.tlds = ImmutableSet.of("foo");
createTlds("bar", "sim"); createTlds("bar", "sim");
persistActiveDomain("dontlist.bar", DateTime.parse("2015-02-14T15:15:15Z")); persistActiveDomain("dontlist.bar", DateTime.parse("2015-02-14T15:15:15Z"));
@ -88,7 +85,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_multipleTlds() { void testRun_multipleTlds() {
action.tlds = ImmutableSet.of("bar", "foo"); action.tlds = ImmutableSet.of("bar", "foo");
createTlds("bar", "sim"); createTlds("bar", "sim");
persistActiveDomain("dolist.bar", DateTime.parse("2015-01-15T15:15:15Z")); persistActiveDomain("dolist.bar", DateTime.parse("2015-01-15T15:15:15Z"));
@ -106,7 +103,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_moreTldsThanMaxNumSubqueries() { void testRun_moreTldsThanMaxNumSubqueries() {
ListDomainsAction.maxNumSubqueries = 2; ListDomainsAction.maxNumSubqueries = 2;
createTlds("baa", "bab", "bac", "bad"); createTlds("baa", "bab", "bac", "bad");
action.tlds = ImmutableSet.of("baa", "bab", "bac", "bad"); action.tlds = ImmutableSet.of("baa", "bab", "bac", "bad");
@ -129,7 +126,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_twoLinesWithIdOnlyNoHeader() { void testRun_twoLinesWithIdOnlyNoHeader() {
action.tlds = ImmutableSet.of("foo"); action.tlds = ImmutableSet.of("foo");
persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z")); persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z"));
persistActiveDomain("example2.foo", DateTime.parse("2011-03-04T16:00:00Z")); persistActiveDomain("example2.foo", DateTime.parse("2011-03-04T16:00:00Z"));
@ -143,7 +140,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_twoLinesWithIdOnlyExplicitHeader() { void testRun_twoLinesWithIdOnlyExplicitHeader() {
action.tlds = ImmutableSet.of("foo"); action.tlds = ImmutableSet.of("foo");
persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z")); persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z"));
persistActiveDomain("example2.foo", DateTime.parse("2011-03-04T16:00:00Z")); persistActiveDomain("example2.foo", DateTime.parse("2011-03-04T16:00:00Z"));
@ -159,7 +156,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_twoLinesWithRepoId() { void testRun_twoLinesWithRepoId() {
action.tlds = ImmutableSet.of("foo"); action.tlds = ImmutableSet.of("foo");
persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z")); persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z"));
persistActiveDomain("example3.foo", DateTime.parse("2011-03-04T16:00:00Z")); persistActiveDomain("example3.foo", DateTime.parse("2011-03-04T16:00:00Z"));
@ -175,7 +172,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_twoLinesWithRepoIdNoHeader() { void testRun_twoLinesWithRepoIdNoHeader() {
action.tlds = ImmutableSet.of("foo"); action.tlds = ImmutableSet.of("foo");
persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z")); persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z"));
persistActiveDomain("example3.foo", DateTime.parse("2011-03-04T16:00:00Z")); persistActiveDomain("example3.foo", DateTime.parse("2011-03-04T16:00:00Z"));
@ -189,7 +186,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_twoLinesWithRepoIdExplicitHeader() { void testRun_twoLinesWithRepoIdExplicitHeader() {
action.tlds = ImmutableSet.of("foo"); action.tlds = ImmutableSet.of("foo");
persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z")); persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z"));
persistActiveDomain("example3.foo", DateTime.parse("2011-03-04T16:00:00Z")); persistActiveDomain("example3.foo", DateTime.parse("2011-03-04T16:00:00Z"));
@ -205,7 +202,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_twoLinesWithWildcard() { void testRun_twoLinesWithWildcard() {
action.tlds = ImmutableSet.of("foo"); action.tlds = ImmutableSet.of("foo");
persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z")); persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z"));
persistActiveDomain("example3.foo", DateTime.parse("2010-03-05T16:00:00Z")); persistActiveDomain("example3.foo", DateTime.parse("2010-03-05T16:00:00Z"));
@ -221,7 +218,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_twoLinesWithWildcardAndAnotherField() { void testRun_twoLinesWithWildcardAndAnotherField() {
action.tlds = ImmutableSet.of("foo"); action.tlds = ImmutableSet.of("foo");
persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z")); persistActiveDomain("example1.foo", DateTime.parse("2010-03-04T16:00:00Z"));
persistActiveDomain("example3.foo", DateTime.parse("2010-03-04T17:00:00Z")); persistActiveDomain("example3.foo", DateTime.parse("2010-03-04T17:00:00Z"));
@ -237,7 +234,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withBadField_returnsError() { void testRun_withBadField_returnsError() {
action.tlds = ImmutableSet.of("foo"); action.tlds = ImmutableSet.of("foo");
persistActiveDomain("example2.foo"); persistActiveDomain("example2.foo");
persistActiveDomain("example1.foo"); persistActiveDomain("example1.foo");
@ -250,7 +247,7 @@ public class ListDomainsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_limitFiltersOutOldestDomains() { void testRun_limitFiltersOutOldestDomains() {
createTlds("bar", "baz"); createTlds("bar", "baz");
action.tlds = ImmutableSet.of("foo", "bar"); action.tlds = ImmutableSet.of("foo", "bar");
action.limit = 2; action.limit = 2;

View file

@ -20,28 +20,23 @@ import static google.registry.testing.DatastoreHelper.persistActiveHost;
import google.registry.testing.FakeClock; import google.registry.testing.FakeClock;
import java.util.Optional; import java.util.Optional;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** /** Unit tests for {@link ListHostsAction}. */
* Unit tests for {@link ListHostsAction}. class ListHostsActionTest extends ListActionTestCase {
*/
@RunWith(JUnit4.class)
public class ListHostsActionTest extends ListActionTestCase {
ListHostsAction action; private ListHostsAction action;
@Before @BeforeEach
public void init() { void beforeEach() {
createTld("foo"); createTld("foo");
action = new ListHostsAction(); action = new ListHostsAction();
action.clock = new FakeClock(DateTime.parse("2000-01-01TZ")); action.clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
} }
@Test @Test
public void testRun_noParameters() { void testRun_noParameters() {
testRunSuccess( testRunSuccess(
action, action,
null, null,
@ -50,7 +45,7 @@ public class ListHostsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_twoLinesWithRepoId() { void testRun_twoLinesWithRepoId() {
persistActiveHost("example2.foo"); persistActiveHost("example2.foo");
persistActiveHost("example1.foo"); persistActiveHost("example1.foo");
testRunSuccess( testRunSuccess(
@ -65,7 +60,7 @@ public class ListHostsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_twoLinesWithWildcard() { void testRun_twoLinesWithWildcard() {
persistActiveHost("example2.foo"); persistActiveHost("example2.foo");
persistActiveHost("example1.foo"); persistActiveHost("example1.foo");
testRunSuccess( testRunSuccess(
@ -80,7 +75,7 @@ public class ListHostsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_twoLinesWithWildcardAndAnotherField() { void testRun_twoLinesWithWildcardAndAnotherField() {
persistActiveHost("example2.foo"); persistActiveHost("example2.foo");
persistActiveHost("example1.foo"); persistActiveHost("example1.foo");
testRunSuccess( testRunSuccess(
@ -95,7 +90,7 @@ public class ListHostsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withBadField_returnsError() { void testRun_withBadField_returnsError() {
persistActiveHost("example2.foo"); persistActiveHost("example2.foo");
persistActiveHost("example1.foo"); persistActiveHost("example1.foo");
testRunError( testRunError(

View file

@ -17,28 +17,23 @@ package google.registry.tools.server;
import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistPremiumList;
import java.util.Optional; import java.util.Optional;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** /** Unit tests for {@link ListPremiumListsAction}. */
* Unit tests for {@link ListPremiumListsAction}. class ListPremiumListsActionTest extends ListActionTestCase {
*/
@RunWith(JUnit4.class)
public class ListPremiumListsActionTest extends ListActionTestCase {
ListPremiumListsAction action; private ListPremiumListsAction action;
@Before @BeforeEach
public void init() { void beforeEach() {
persistPremiumList("xn--q9jyb4c", "rich,USD 100"); persistPremiumList("xn--q9jyb4c", "rich,USD 100");
persistPremiumList("how", "richer,JPY 5000"); persistPremiumList("how", "richer,JPY 5000");
action = new ListPremiumListsAction(); action = new ListPremiumListsAction();
} }
@Test @Test
public void testRun_noParameters() { void testRun_noParameters() {
testRunSuccess( testRunSuccess(
action, action,
Optional.empty(), Optional.empty(),
@ -49,7 +44,7 @@ public class ListPremiumListsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withParameters() { void testRun_withParameters() {
testRunSuccess( testRunSuccess(
action, action,
Optional.of("revisionKey"), Optional.of("revisionKey"),
@ -62,7 +57,7 @@ public class ListPremiumListsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withWildcard() { void testRun_withWildcard() {
testRunSuccess( testRunSuccess(
action, action,
Optional.of("*"), Optional.of("*"),
@ -75,7 +70,7 @@ public class ListPremiumListsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withBadField_returnsError() { void testRun_withBadField_returnsError() {
testRunError( testRunError(
action, action,
Optional.of("badfield"), Optional.of("badfield"),

View file

@ -20,21 +20,16 @@ import static google.registry.testing.DatastoreHelper.persistResource;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import java.util.Optional; import java.util.Optional;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** /** Unit tests for {@link ListRegistrarsAction}. */
* Unit tests for {@link ListRegistrarsAction}. class ListRegistrarsActionTest extends ListActionTestCase {
*/
@RunWith(JUnit4.class)
public class ListRegistrarsActionTest extends ListActionTestCase {
ListRegistrarsAction action; private ListRegistrarsAction action;
@Before @BeforeEach
public void init() { void beforeEach() {
action = new ListRegistrarsAction(); action = new ListRegistrarsAction();
createTlds("xn--q9jyb4c", "example"); createTlds("xn--q9jyb4c", "example");
// Ensure that NewRegistrar only has access to xn--q9jyb4c and that TheRegistrar only has access // Ensure that NewRegistrar only has access to xn--q9jyb4c and that TheRegistrar only has access
@ -52,7 +47,7 @@ public class ListRegistrarsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_noParameters() { void testRun_noParameters() {
testRunSuccess( testRunSuccess(
action, action,
Optional.empty(), Optional.empty(),
@ -63,7 +58,7 @@ public class ListRegistrarsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withParameters() { void testRun_withParameters() {
testRunSuccess( testRunSuccess(
action, action,
Optional.of("allowedTlds"), Optional.of("allowedTlds"),
@ -76,7 +71,7 @@ public class ListRegistrarsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withWildcard() { void testRun_withWildcard() {
testRunSuccess( testRunSuccess(
action, action,
Optional.of("*"), Optional.of("*"),
@ -89,7 +84,7 @@ public class ListRegistrarsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withBadField_returnsError() { void testRun_withBadField_returnsError() {
testRunError( testRunError(
action, action,
Optional.of("badfield"), Optional.of("badfield"),

View file

@ -21,21 +21,16 @@ import static google.registry.testing.DatastoreHelper.persistResource;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.label.ReservedList; import google.registry.model.registry.label.ReservedList;
import java.util.Optional; import java.util.Optional;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** /** Unit tests for {@link ListReservedListsAction}. */
* Unit tests for {@link ListReservedListsAction}. class ListReservedListsActionTest extends ListActionTestCase {
*/
@RunWith(JUnit4.class)
public class ListReservedListsActionTest extends ListActionTestCase {
ListReservedListsAction action; private ListReservedListsAction action;
@Before @BeforeEach
public void init() { void beforeEach() {
ReservedList rl1 = persistReservedList("xn--q9jyb4c-published", true, "blah,FULLY_BLOCKED"); ReservedList rl1 = persistReservedList("xn--q9jyb4c-published", true, "blah,FULLY_BLOCKED");
ReservedList rl2 = persistReservedList("xn--q9jyb4c-private", false, "dugong,FULLY_BLOCKED"); ReservedList rl2 = persistReservedList("xn--q9jyb4c-private", false, "dugong,FULLY_BLOCKED");
createTld("xn--q9jyb4c"); createTld("xn--q9jyb4c");
@ -44,7 +39,7 @@ public class ListReservedListsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_noParameters() { void testRun_noParameters() {
testRunSuccess( testRunSuccess(
action, action,
Optional.empty(), Optional.empty(),
@ -55,7 +50,7 @@ public class ListReservedListsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withParameters() { void testRun_withParameters() {
testRunSuccess( testRunSuccess(
action, action,
Optional.of("shouldPublish"), Optional.of("shouldPublish"),
@ -68,7 +63,7 @@ public class ListReservedListsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withWildcard() { void testRun_withWildcard() {
testRunSuccess( testRunSuccess(
action, action,
Optional.of("*"), Optional.of("*"),
@ -81,7 +76,7 @@ public class ListReservedListsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withBadField_returnsError() { void testRun_withBadField_returnsError() {
testRunError( testRunError(
action, action,
Optional.of("badfield"), Optional.of("badfield"),

View file

@ -19,31 +19,28 @@ import static google.registry.testing.DatastoreHelper.createTld;
import google.registry.testing.FakeClock; import google.registry.testing.FakeClock;
import java.util.Optional; import java.util.Optional;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link ListTldsAction}. */ /** Unit tests for {@link ListTldsAction}. */
@RunWith(JUnit4.class) class ListTldsActionTest extends ListActionTestCase {
public class ListTldsActionTest extends ListActionTestCase {
ListTldsAction action; private ListTldsAction action;
@Before @BeforeEach
public void init() { void beforeEach() {
createTld("xn--q9jyb4c"); createTld("xn--q9jyb4c");
action = new ListTldsAction(); action = new ListTldsAction();
action.clock = new FakeClock(DateTime.parse("2000-01-01TZ")); action.clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
} }
@Test @Test
public void testRun_noParameters() { void testRun_noParameters() {
testRunSuccess(action, Optional.empty(), Optional.empty(), Optional.empty(), "xn--q9jyb4c"); testRunSuccess(action, Optional.empty(), Optional.empty(), Optional.empty(), "xn--q9jyb4c");
} }
@Test @Test
public void testRun_withParameters() { void testRun_withParameters() {
testRunSuccess( testRunSuccess(
action, action,
Optional.of("tldType"), Optional.of("tldType"),
@ -55,7 +52,7 @@ public class ListTldsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withWildcard() { void testRun_withWildcard() {
testRunSuccess( testRunSuccess(
action, action,
Optional.of("*"), Optional.of("*"),
@ -67,7 +64,7 @@ public class ListTldsActionTest extends ListActionTestCase {
} }
@Test @Test
public void testRun_withBadField_returnsError() { void testRun_withBadField_returnsError() {
testRunError( testRunError(
action, action,
Optional.of("badfield"), Optional.of("badfield"),

View file

@ -32,24 +32,21 @@ import google.registry.testing.DatastoreHelper;
import google.registry.testing.FakeJsonResponse; import google.registry.testing.FakeJsonResponse;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.joda.money.Money; import org.joda.money.Money;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link UpdatePremiumListAction}. */ /** Unit tests for {@link UpdatePremiumListAction}. */
@RunWith(JUnit4.class) class UpdatePremiumListActionTest {
public class UpdatePremiumListActionTest {
@Rule @RegisterExtension
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
UpdatePremiumListAction action; private UpdatePremiumListAction action;
FakeJsonResponse response; private FakeJsonResponse response;
@Before @BeforeEach
public void init() { void beforeEach() {
createTlds("foo", "xn--q9jyb4c", "how"); createTlds("foo", "xn--q9jyb4c", "how");
action = new UpdatePremiumListAction(); action = new UpdatePremiumListAction();
response = new FakeJsonResponse(); response = new FakeJsonResponse();
@ -57,14 +54,14 @@ public class UpdatePremiumListActionTest {
} }
@Test @Test
public void test_invalidRequest_missingInput_returnsErrorStatus() { void test_invalidRequest_missingInput_returnsErrorStatus() {
action.name = "foo"; action.name = "foo";
action.run(); action.run();
assertThat(response.getResponseMap().get("status")).isEqualTo("error"); assertThat(response.getResponseMap().get("status")).isEqualTo("error");
} }
@Test @Test
public void test_invalidRequest_listDoesNotExist_returnsErrorStatus() { void test_invalidRequest_listDoesNotExist_returnsErrorStatus() {
action.name = "bamboozle"; action.name = "bamboozle";
action.inputData = "richer,JPY 5000"; action.inputData = "richer,JPY 5000";
action.run(); action.run();
@ -76,7 +73,7 @@ public class UpdatePremiumListActionTest {
} }
@Test @Test
public void test_success() { void test_success() {
PremiumListDao.saveNew( PremiumListDao.saveNew(
parseToPremiumList( parseToPremiumList(
"foo", readResourceUtf8(DatastoreHelper.class, "default_premium_list_testdata.csv"))); "foo", readResourceUtf8(DatastoreHelper.class, "default_premium_list_testdata.csv")));

View file

@ -22,36 +22,33 @@ import google.registry.model.OteStatsTestHelper;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link VerifyOteAction}. */ /** Unit tests for {@link VerifyOteAction}. */
@RunWith(JUnit4.class) class VerifyOteActionTest {
public class VerifyOteActionTest {
@Rule @RegisterExtension
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private final VerifyOteAction action = new VerifyOteAction(); private final VerifyOteAction action = new VerifyOteAction();
@Test @Test
public void testSuccess_summarize_allPass() throws Exception { void testSuccess_summarize_allPass() throws Exception {
OteStatsTestHelper.setupCompleteOte("blobio"); OteStatsTestHelper.setupCompleteOte("blobio");
assertThat(getResponse(true)) assertThat(getResponse(true))
.isEqualTo("# actions: 30 - Reqs: [----------------] 16/16 - Overall: PASS"); .isEqualTo("# actions: 30 - Reqs: [----------------] 16/16 - Overall: PASS");
} }
@Test @Test
public void testFailure_summarize_someFailures() throws Exception { void testFailure_summarize_someFailures() throws Exception {
OteStatsTestHelper.setupIncompleteOte("blobio"); OteStatsTestHelper.setupIncompleteOte("blobio");
assertThat(getResponse(true)) assertThat(getResponse(true))
.isEqualTo("# actions: 34 - Reqs: [-.-----.------.-] 13/16 - Overall: FAIL"); .isEqualTo("# actions: 34 - Reqs: [-.-----.------.-] 13/16 - Overall: FAIL");
} }
@Test @Test
public void testSuccess_passNotSummarized() throws Exception { void testSuccess_passNotSummarized() throws Exception {
OteStatsTestHelper.setupCompleteOte("blobio"); OteStatsTestHelper.setupCompleteOte("blobio");
String expectedOteStatus = String expectedOteStatus =
"domain creates idn: 1\n" "domain creates idn: 1\n"
@ -81,7 +78,7 @@ public class VerifyOteActionTest {
} }
@Test @Test
public void testFailure_incomplete() throws Exception { void testFailure_incomplete() throws Exception {
OteStatsTestHelper.setupIncompleteOte("blobio"); OteStatsTestHelper.setupIncompleteOte("blobio");
String expectedOteStatus = String expectedOteStatus =
"domain creates idn: 0\n" "domain creates idn: 0\n"

View file

@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.networking.handler.SslInitializerTestUtils.getKeyPair; import static google.registry.networking.handler.SslInitializerTestUtils.getKeyPair;
import static google.registry.networking.handler.SslInitializerTestUtils.setUpSslChannel; import static google.registry.networking.handler.SslInitializerTestUtils.setUpSslChannel;
import static google.registry.networking.handler.SslInitializerTestUtils.signKeyPair; import static google.registry.networking.handler.SslInitializerTestUtils.signKeyPair;
import static google.registry.networking.handler.SslInitializerTestUtils.verifySslExcpetion; import static google.registry.networking.handler.SslInitializerTestUtils.verifySslException;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import google.registry.networking.util.SelfSignedCaCertificate; import google.registry.networking.util.SelfSignedCaCertificate;
@ -225,7 +225,7 @@ public class SslClientInitializerTest {
sslProvider, hostProvider, portProvider, ImmutableList.of(ssc.cert()), null, null); sslProvider, hostProvider, portProvider, ImmutableList.of(ssc.cert()), null, null);
nettyRule.setUpClient(localAddress, sslClientInitializer); nettyRule.setUpClient(localAddress, sslClientInitializer);
verifySslExcpetion( verifySslException(
nettyRule.getClientChannel(), nettyRule.getClientChannel(),
channel -> channel.pipeline().get(SslHandler.class).handshakeFuture().get(), channel -> channel.pipeline().get(SslHandler.class).handshakeFuture().get(),
CertificateExpiredException.class); CertificateExpiredException.class);
@ -259,7 +259,7 @@ public class SslClientInitializerTest {
sslProvider, hostProvider, portProvider, ImmutableList.of(ssc.cert()), null, null); sslProvider, hostProvider, portProvider, ImmutableList.of(ssc.cert()), null, null);
nettyRule.setUpClient(localAddress, sslClientInitializer); nettyRule.setUpClient(localAddress, sslClientInitializer);
verifySslExcpetion( verifySslException(
nettyRule.getClientChannel(), nettyRule.getClientChannel(),
channel -> channel.pipeline().get(SslHandler.class).handshakeFuture().get(), channel -> channel.pipeline().get(SslHandler.class).handshakeFuture().get(),
CertificateNotYetValidException.class); CertificateNotYetValidException.class);

View file

@ -128,7 +128,7 @@ public final class SslInitializerTestUtils {
} }
/** Verifies tha the SSL channel cannot be established due to a given exception. */ /** Verifies tha the SSL channel cannot be established due to a given exception. */
static void verifySslExcpetion( static void verifySslException(
Channel channel, CheckedConsumer<Channel> operation, Class<? extends Exception> cause) Channel channel, CheckedConsumer<Channel> operation, Class<? extends Exception> cause)
throws Exception { throws Exception {
// Extract SSL exception from the handshake future. // Extract SSL exception from the handshake future.

View file

@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.networking.handler.SslInitializerTestUtils.getKeyPair; import static google.registry.networking.handler.SslInitializerTestUtils.getKeyPair;
import static google.registry.networking.handler.SslInitializerTestUtils.setUpSslChannel; import static google.registry.networking.handler.SslInitializerTestUtils.setUpSslChannel;
import static google.registry.networking.handler.SslInitializerTestUtils.signKeyPair; import static google.registry.networking.handler.SslInitializerTestUtils.signKeyPair;
import static google.registry.networking.handler.SslInitializerTestUtils.verifySslExcpetion; import static google.registry.networking.handler.SslInitializerTestUtils.verifySslException;
import static google.registry.networking.handler.SslServerInitializer.CLIENT_CERTIFICATE_PROMISE_KEY; import static google.registry.networking.handler.SslServerInitializer.CLIENT_CERTIFICATE_PROMISE_KEY;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
@ -181,7 +181,7 @@ public class SslServerInitializerTest {
nettyRule.setUpClient( nettyRule.setUpClient(
localAddress, getClientHandler(serverSsc.cert(), clientSsc.key(), clientSsc.cert())); localAddress, getClientHandler(serverSsc.cert(), clientSsc.key(), clientSsc.cert()));
verifySslExcpetion( verifySslException(
nettyRule.getServerChannel(), nettyRule.getServerChannel(),
channel -> channel.attr(CLIENT_CERTIFICATE_PROMISE_KEY).get().get(), channel -> channel.attr(CLIENT_CERTIFICATE_PROMISE_KEY).get().get(),
CertificateExpiredException.class); CertificateExpiredException.class);
@ -202,7 +202,7 @@ public class SslServerInitializerTest {
nettyRule.setUpClient( nettyRule.setUpClient(
localAddress, getClientHandler(serverSsc.cert(), clientSsc.key(), clientSsc.cert())); localAddress, getClientHandler(serverSsc.cert(), clientSsc.key(), clientSsc.cert()));
verifySslExcpetion( verifySslException(
nettyRule.getServerChannel(), nettyRule.getServerChannel(),
channel -> channel.attr(CLIENT_CERTIFICATE_PROMISE_KEY).get().get(), channel -> channel.attr(CLIENT_CERTIFICATE_PROMISE_KEY).get().get(),
CertificateNotYetValidException.class); CertificateNotYetValidException.class);