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

View file

@ -20,67 +20,65 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.joda.time.Duration;
import org.joda.time.Period;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link DurationParameter}. */
@RunWith(JUnit4.class)
public class DurationParameterTest {
class DurationParameterTest {
private final DurationParameter instance = new DurationParameter();
@Test
public void testConvert_isoHours() {
void testConvert_isoHours() {
assertThat(instance.convert("PT36H")).isEqualTo(Duration.standardHours(36));
}
@Test
public void testConvert_isoDaysAndHours() {
void testConvert_isoDaysAndHours() {
assertThat(instance.convert("P1DT12H")).isEqualTo(Duration.standardHours(36));
}
@Test
public void testConvert_isoLowercase_isAllowed() {
void testConvert_isoLowercase_isAllowed() {
assertThat(instance.convert("pt36h")).isEqualTo(Duration.standardHours(36));
}
@Test
public void testIsoMissingP_notAllowed() {
void testIsoMissingP_notAllowed() {
assertThrows(IllegalArgumentException.class, () -> Period.parse("T36H"));
}
@Test
public void testIsoMissingPT_notAllowed() {
void testIsoMissingPT_notAllowed() {
assertThrows(IllegalArgumentException.class, () -> Period.parse("36H"));
}
@Test
public void testConvert_isoMissingP_notAllowed() {
void testConvert_isoMissingP_notAllowed() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("T36H"));
}
@Test
public void testConvert_null_throws() {
void testConvert_null_throws() {
assertThrows(NullPointerException.class, () -> instance.convert(null));
}
@Test
public void testConvert_empty_throws() {
void testConvert_empty_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
}
@Test
public void testConvert_numeric_throws() {
void testConvert_numeric_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("1234"));
}
@Test
public void testConvert_sillyString_throws() {
void testConvert_sillyString_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
}
@Test
public void testValidate_sillyString_throws() {
void testValidate_sillyString_throws() {
ParameterException thrown =
assertThrows(ParameterException.class, () -> instance.validate("--time", "foo"));
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 google.registry.model.registry.Registry.TldState;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link EnumParameter}. */
@RunWith(JUnit4.class)
public class EnumParameterTest {
class EnumParameterTest {
// 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();
@Test
public void testSuccess_convertEnum() {
void testSuccess_convertEnum() {
assertThat(instance.convert("PREDELEGATION")).isEqualTo(TldState.PREDELEGATION);
}
@Test
public void testFailure_badValue() {
void testFailure_badValue() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> instance.convert("FREE_DOMAINS"));
assertThat(thrown)

View file

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

View file

@ -20,17 +20,15 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.joda.time.DateTime;
import org.joda.time.Interval;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link IntervalParameter}. */
@RunWith(JUnit4.class)
public class IntervalParameterTest {
class IntervalParameterTest {
private final IntervalParameter instance = new IntervalParameter();
@Test
public void testConvert() {
void testConvert() {
assertThat(instance.convert("2004-06-09T12:30:00Z/2004-07-10T13:30:00Z"))
.isEqualTo(new Interval(
DateTime.parse("2004-06-09T12:30:00Z"),
@ -38,34 +36,34 @@ public class IntervalParameterTest {
}
@Test
public void testConvert_singleDate() {
void testConvert_singleDate() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2004-06-09T12:30:00Z"));
}
@Test
public void testConvert_backwardsInterval() {
void testConvert_backwardsInterval() {
assertThrows(
IllegalArgumentException.class,
() -> instance.convert("2004-07-10T13:30:00Z/2004-06-09T12:30:00Z"));
}
@Test
public void testConvert_empty_throws() {
void testConvert_empty_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
}
@Test
public void testConvert_null_throws() {
void testConvert_null_throws() {
assertThrows(NullPointerException.class, () -> instance.convert(null));
}
@Test
public void testConvert_sillyString_throws() {
void testConvert_sillyString_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
}
@Test
public void testValidate_sillyString_throws() {
void testValidate_sillyString_throws() {
ParameterException thrown =
assertThrows(ParameterException.class, () -> instance.validate("--time", "foo"));
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 org.joda.money.CurrencyUnit;
import org.joda.money.IllegalCurrencyException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link KeyValueMapParameter}. */
@RunWith(JUnit4.class)
public class KeyValueMapParameterTest {
class KeyValueMapParameterTest {
private final StringToStringMap stringToStringInstance = new StringToStringMap();
private final StringToIntegerMap stringToIntegerInstance = new StringToIntegerMap();
private final CurrencyUnitToStringMap currencyUnitToStringMap = new CurrencyUnitToStringMap();
@Test
public void testSuccess_convertStringToString_singleEntry() {
void testSuccess_convertStringToString_singleEntry() {
assertThat(stringToStringInstance.convert("key=foo"))
.isEqualTo(ImmutableMap.of("key", "foo"));
}
@Test
public void testSuccess_convertStringToInteger_singleEntry() {
void testSuccess_convertStringToInteger_singleEntry() {
assertThat(stringToIntegerInstance.convert("key=1"))
.isEqualTo(ImmutableMap.of("key", 1));
}
@Test
public void testSuccess_convertCurrencyUnitToString_singleEntry() {
void testSuccess_convertCurrencyUnitToString_singleEntry() {
assertThat(currencyUnitToStringMap.convert("USD=123abc"))
.isEqualTo(ImmutableMap.of(CurrencyUnit.USD, "123abc"));
}
@Test
public void testSuccess_convertStringToString() {
void testSuccess_convertStringToString() {
assertThat(stringToStringInstance.convert("key=foo,key2=bar"))
.isEqualTo(ImmutableMap.of("key", "foo", "key2", "bar"));
}
@Test
public void testSuccess_convertStringToInteger() {
void testSuccess_convertStringToInteger() {
assertThat(stringToIntegerInstance.convert("key=1,key2=2"))
.isEqualTo(ImmutableMap.of("key", 1, "key2", 2));
}
@Test
public void testSuccess_convertCurrencyUnitToString() {
void testSuccess_convertCurrencyUnitToString() {
assertThat(currencyUnitToStringMap.convert("USD=123abc,JPY=xyz789"))
.isEqualTo(ImmutableMap.of(CurrencyUnit.USD, "123abc", CurrencyUnit.JPY, "xyz789"));
}
@Test
public void testSuccess_convertStringToString_empty() {
void testSuccess_convertStringToString_empty() {
assertThat(stringToStringInstance.convert("")).isEmpty();
}
@Test
public void testSuccess_convertStringToInteger_empty() {
void testSuccess_convertStringToInteger_empty() {
assertThat(stringToIntegerInstance.convert("")).isEmpty();
}
@Test
public void testSuccess_convertCurrencyUnitToString_empty() {
void testSuccess_convertCurrencyUnitToString_empty() {
assertThat(currencyUnitToStringMap.convert("")).isEmpty();
}
@Test
public void testFailure_convertStringToInteger_badType() {
void testFailure_convertStringToInteger_badType() {
assertThrows(
NumberFormatException.class, () -> stringToIntegerInstance.convert("key=1,key2=foo"));
}
@Test
public void testFailure_convertCurrencyUnitToString_badType() {
void testFailure_convertCurrencyUnitToString_badType() {
IllegalCurrencyException thrown =
assertThrows(
IllegalCurrencyException.class,
@ -101,36 +99,36 @@ public class KeyValueMapParameterTest {
}
@Test
public void testFailure_convertStringToString_badSeparator() {
void testFailure_convertStringToString_badSeparator() {
assertThrows(
IllegalArgumentException.class, () -> stringToStringInstance.convert("key=foo&key2=bar"));
}
@Test
public void testFailure_convertStringToInteger_badSeparator() {
void testFailure_convertStringToInteger_badSeparator() {
assertThrows(
IllegalArgumentException.class, () -> stringToIntegerInstance.convert("key=1&key2=2"));
}
@Test
public void testFailure_convertCurrencyUnitToString_badSeparator() {
void testFailure_convertCurrencyUnitToString_badSeparator() {
assertThrows(
IllegalArgumentException.class,
() -> currencyUnitToStringMap.convert("USD=123abc&JPY=xyz789"));
}
@Test
public void testFailure_convertStringToString_badFormat() {
void testFailure_convertStringToString_badFormat() {
assertThrows(IllegalArgumentException.class, () -> stringToStringInstance.convert("foo"));
}
@Test
public void testFailure_convertStringToInteger_badFormat() {
void testFailure_convertStringToInteger_badFormat() {
assertThrows(IllegalArgumentException.class, () -> stringToIntegerInstance.convert("foo"));
}
@Test
public void testFailure_convertCurrencyUnitToString_badFormat() {
void testFailure_convertCurrencyUnitToString_badFormat() {
assertThrows(IllegalArgumentException.class, () -> currencyUnitToStringMap.convert("foo"));
}
}

View file

@ -19,64 +19,62 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.joda.money.Money;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link MoneyParameter}. */
@RunWith(JUnit4.class)
public class MoneyParameterTest {
class MoneyParameterTest {
private final MoneyParameter instance = new MoneyParameter();
@Test
public void testConvert_withCurrency() {
void testConvert_withCurrency() {
assertThat(instance.convert("USD 777.99")).isEqualTo(Money.parse("USD 777.99"));
}
@Test
public void testConvert_negative() {
void testConvert_negative() {
assertThat(instance.convert("USD -777.99")).isEqualTo(Money.parse("USD -777.99"));
}
@Test
public void testConvert_missingSpace_isForgiving() {
void testConvert_missingSpace_isForgiving() {
assertThat(instance.convert("USD777.99")).isEqualTo(Money.parse("USD 777.99"));
}
@Test
public void testConvert_lowercase_isForgiving() {
void testConvert_lowercase_isForgiving() {
assertThat(instance.convert("usd777.99")).isEqualTo(Money.parse("USD 777.99"));
}
@Test
public void testConvert_badCurrency_throws() {
void testConvert_badCurrency_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("FOO 1337"));
}
@Test
public void testConvert_null_throws() {
void testConvert_null_throws() {
assertThrows(NullPointerException.class, () -> instance.convert(null));
}
@Test
public void testConvert_empty_throws() {
void testConvert_empty_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
}
@Test
public void testConvert_sillyString_throws() {
void testConvert_sillyString_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
}
@Test
public void testValidate_sillyString_throws() {
void testValidate_sillyString_throws() {
ParameterException thrown =
assertThrows(ParameterException.class, () -> instance.validate("--money", "foo"));
assertThat(thrown).hasMessageThat().contains("--money=foo not valid");
}
@Test
public void testValidate_correctInput() {
void testValidate_correctInput() {
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 com.beust.jcommander.ParameterException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link NameserversParameter}. */
@RunWith(JUnit4.class)
public class NameserversParameterTest {
class NameserversParameterTest {
private final NameserversParameter instance = new NameserversParameter();
@Test
public void testConvert_singleBasicNameserver() {
void testConvert_singleBasicNameserver() {
assertThat(instance.convert("ns11.goes.to")).containsExactly("ns11.goes.to");
}
@Test
public void testConvert_multipleBasicNameservers() {
void testConvert_multipleBasicNameservers() {
assertThat(instance.convert("ns1.tim.buktu, ns2.tim.buktu, ns3.tim.buktu"))
.containsExactly("ns1.tim.buktu", "ns2.tim.buktu", "ns3.tim.buktu");
}
@Test
public void testConvert_kitchenSink() {
void testConvert_kitchenSink() {
assertThat(instance.convert(" ns1.foo.bar, ,ns2.foo.bar,, ns[1-3].range.baz "))
.containsExactly(
"ns1.foo.bar", "ns2.foo.bar", "ns1.range.baz", "ns2.range.baz", "ns3.range.baz");
}
@Test
public void testConvert_invalid() {
void testConvert_invalid() {
assertThat(instance.convert("ns1.foo.bar,ns2.foo.baz,ns3.foo.bar"))
.containsExactly("ns1.foo.bar", "ns3.foo.bar", "ns2.foo.baz");
}
@Test
public void testValidate_sillyString_throws() {
void testValidate_sillyString_throws() {
ParameterException thrown =
assertThrows(ParameterException.class, () -> instance.validate("nameservers", "[[ns]]"));
assertThat(thrown).hasMessageThat().contains("Must be a comma-delimited list of nameservers");
@ -63,40 +60,40 @@ public class NameserversParameterTest {
}
@Test
public void testConvert_empty_returnsEmpty() {
void testConvert_empty_returnsEmpty() {
assertThat(instance.convert("")).isEmpty();
}
@Test
public void testConvert_nullString_returnsNull() {
void testConvert_nullString_returnsNull() {
assertThat(instance.convert(null)).isEmpty();
}
@Test
public void testSplitNameservers_noopWithNoBrackets() {
void testSplitNameservers_noopWithNoBrackets() {
assertThat(splitNameservers("ns9.fake.example")).containsExactly("ns9.fake.example");
}
@Test
public void testSplitNameservers_worksWithBrackets() {
void testSplitNameservers_worksWithBrackets() {
assertThat(splitNameservers("ns[1-4].zan.zibar"))
.containsExactly("ns1.zan.zibar", "ns2.zan.zibar", "ns3.zan.zibar", "ns4.zan.zibar");
}
@Test
public void testSplitNameservers_worksWithBrackets_soloRange() {
void testSplitNameservers_worksWithBrackets_soloRange() {
assertThat(splitNameservers("ns[1-1].zan.zibar")).containsExactly("ns1.zan.zibar");
}
@Test
public void testSplitNameservers_throwsOnInvalidRange() {
void testSplitNameservers_throwsOnInvalidRange() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> splitNameservers("ns[9-2].foo.bar"));
assertThat(thrown).hasMessageThat().isEqualTo("Number range [9-2] is invalid");
}
@Test
public void testSplitNameservers_throwsOnInvalidHostname_missingPrefix() {
void testSplitNameservers_throwsOnInvalidHostname_missingPrefix() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> splitNameservers("[1-4].foo.bar"));
assertThat(thrown)
@ -105,7 +102,7 @@ public class NameserversParameterTest {
}
@Test
public void testSplitNameservers_throwsOnInvalidHostname_missingDomainName() {
void testSplitNameservers_throwsOnInvalidHostname_missingDomainName() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> splitNameservers("this.is.ns[1-5]"));
assertThat(thrown)
@ -114,7 +111,7 @@ public class NameserversParameterTest {
}
@Test
public void testSplitNameservers_throwsOnInvalidRangeSyntax() {
void testSplitNameservers_throwsOnInvalidRangeSyntax() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> splitNameservers("ns[1-4[.foo.bar"));
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.Paths;
import java.nio.file.attribute.PosixFilePermissions;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
/** Unit tests for {@link PathParameter}. */
@RunWith(JUnit4.class)
public class PathParameterTest {
@Rule
public final TemporaryFolder folder = new TemporaryFolder();
class PathParameterTest {
@TempDir Path tmpDir;
// ================================ Test Convert ==============================================
private final PathParameter vanilla = new PathParameter();
@Test
public void testConvert_etcPasswd_returnsPath() {
void testConvert_etcPasswd_returnsPath() {
assertThat((Object) vanilla.convert("/etc/passwd")).isEqualTo(Paths.get("/etc/passwd"));
}
@Test
public void testConvert_null_throws() {
void testConvert_null_throws() {
assertThrows(NullPointerException.class, () -> vanilla.convert(null));
}
@Test
public void testConvert_empty_throws() {
void testConvert_empty_throws() {
assertThrows(IllegalArgumentException.class, () -> vanilla.convert(""));
}
@Test
public void testConvert_relativePath_returnsOriginalFile() throws Exception {
void testConvert_relativePath_returnsOriginalFile() throws Exception {
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);
assumeThat(relative, is(not(equalTo(file))));
assumeThat(relative.toString(), startsWith("../"));
@ -73,13 +69,13 @@ public class PathParameterTest {
}
@Test
public void testConvert_extraSlash_returnsWithoutSlash() throws Exception {
Path file = Paths.get(folder.newFile().toString());
void testConvert_extraSlash_returnsWithoutSlash() throws Exception {
Path file = Paths.get(tmpDir.resolve("file.new").toString());
assertThat((Object) vanilla.convert(file + "/")).isEqualTo(file);
}
@Test
public void testConvert_uriNotProvided() {
void testConvert_uriNotProvided() {
assertThrows(FileSystemNotFoundException.class, () -> vanilla.convert("bog://bucket/lolcat"));
}
@ -88,31 +84,30 @@ public class PathParameterTest {
private final PathParameter inputFile = new PathParameter.InputFile();
@Test
public void testInputFileValidate_normalFile_works() throws Exception {
inputFile.validate("input", folder.newFile().toString());
void testInputFileValidate_normalFile_works() throws Exception {
inputFile.validate("input", Files.createFile(tmpDir.resolve("tmpfile.txt")).toString());
}
@Test
public void testInputFileValidate_missingFile_throws() {
void testInputFileValidate_missingFile_throws() {
ParameterException thrown =
assertThrows(
ParameterException.class,
() -> inputFile.validate("input", new File(folder.getRoot(), "foo").toString()));
() -> inputFile.validate("input", tmpDir.resolve("foo").toString()));
assertThat(thrown).hasMessageThat().contains("not found");
}
@Test
public void testInputFileValidate_directory_throws() {
void testInputFileValidate_directory_throws() {
ParameterException thrown =
assertThrows(
ParameterException.class,
() -> inputFile.validate("input", folder.getRoot().toString()));
ParameterException.class, () -> inputFile.validate("input", tmpDir.toString()));
assertThat(thrown).hasMessageThat().contains("is a directory");
}
@Test
public void testInputFileValidate_unreadableFile_throws() throws Exception {
Path file = Paths.get(folder.newFile().toString());
void testInputFileValidate_unreadableFile_throws() throws Exception {
Path file = Files.createFile(tmpDir.resolve("tmpfile.txt"));
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("-w-------"));
ParameterException thrown =
assertThrows(ParameterException.class, () -> inputFile.validate("input", file.toString()));
@ -124,33 +119,32 @@ public class PathParameterTest {
private final PathParameter outputFile = new PathParameter.OutputFile();
@Test
public void testOutputFileValidate_normalFile_works() throws Exception {
outputFile.validate("input", folder.newFile().toString());
void testOutputFileValidate_normalFile_works() throws Exception {
outputFile.validate("input", tmpDir.resolve("testfile").toString());
}
@Test
public void testInputFileValidate_characterDeviceBehindSymbolicLinks_works() {
void testInputFileValidate_characterDeviceBehindSymbolicLinks_works() {
assumeTrue(Files.exists(Paths.get("/dev/stdin")));
outputFile.validate("input", "/dev/stdin");
}
@Test
public void testOutputFileValidate_missingFile_works() {
outputFile.validate("input", new File(folder.getRoot(), "foo").toString());
void testOutputFileValidate_missingFile_works() {
outputFile.validate("input", new File(tmpDir.toFile(), "foo").toString());
}
@Test
public void testOutputFileValidate_directory_throws() {
void testOutputFileValidate_directory_throws() {
ParameterException thrown =
assertThrows(
ParameterException.class,
() -> outputFile.validate("input", folder.getRoot().toString()));
ParameterException.class, () -> outputFile.validate("input", tmpDir.toString()));
assertThat(thrown).hasMessageThat().contains("is a directory");
}
@Test
public void testOutputFileValidate_notWritable_throws() throws Exception {
Path file = Paths.get(folder.newFile().toString());
void testOutputFileValidate_notWritable_throws() throws Exception {
Path file = Files.createFile(tmpDir.resolve("newFile.dat"));
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("r--------"));
ParameterException thrown =
assertThrows(ParameterException.class, () -> outputFile.validate("input", file.toString()));
@ -158,16 +152,16 @@ public class PathParameterTest {
}
@Test
public void testOutputFileValidate_parentDirMissing_throws() {
Path file = Paths.get(folder.getRoot().toString(), "MISSINGNO", "foo.txt");
void testOutputFileValidate_parentDirMissing_throws() {
Path file = Paths.get(tmpDir.toString(), "MISSINGNO", "foo.txt");
ParameterException thrown =
assertThrows(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");
void testOutputFileValidate_parentDirIsFile_throws() throws Exception {
Path file = Paths.get(Files.createFile(tmpDir.resolve("foo.file")).toString(), "foo.txt");
ParameterException thrown =
assertThrows(ParameterException.class, () -> outputFile.validate("input", file.toString()));
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 org.junit.Assert.assertThrows;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link PhoneNumberParameter}. */
@RunWith(JUnit4.class)
public class PhoneNumberParameterTest {
class PhoneNumberParameterTest {
private final OptionalPhoneNumberParameter instance = new OptionalPhoneNumberParameter();
@Test
public void testConvert_e164() {
void testConvert_e164() {
assertThat(instance.convert("+1.2125550777")).hasValue("+1.2125550777");
}
@Test
public void testConvert_sillyString_throws() {
void testConvert_sillyString_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
}
@Test
public void testConvert_empty_returnsEmpty() {
void testConvert_empty_returnsEmpty() {
assertThat(instance.convert("")).isEmpty();
}
@Test
public void testConvert_nullString_returnsEmpty() {
void testConvert_nullString_returnsEmpty() {
assertThat(instance.convert("null")).isEmpty();
}
}

View file

@ -19,54 +19,52 @@ import static org.junit.Assert.assertThrows;
import com.beust.jcommander.ParameterException;
import org.joda.time.YearMonth;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link YearMonthParameter}. */
@RunWith(JUnit4.class)
public class YearMonthParameterTest {
class YearMonthParameterTest {
private final YearMonthParameter instance = new YearMonthParameter();
@Test
public void testConvert_awfulMonth() {
void testConvert_awfulMonth() {
assertThat(instance.convert("1984-12")).isEqualTo(new YearMonth(1984, 12));
}
@Test
public void testConvert_null_throwsException() {
void testConvert_null_throwsException() {
assertThrows(NullPointerException.class, () -> instance.convert(null));
}
@Test
public void testConvert_empty_throwsException() {
void testConvert_empty_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
}
@Test
public void testConvert_sillyString_throwsException() {
void testConvert_sillyString_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
}
@Test
public void testConvert_wrongOrder() {
void testConvert_wrongOrder() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("12-1984"));
}
@Test
public void testConvert_noHyphen() {
void testConvert_noHyphen() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("198412"));
}
@Test
public void testValidate_sillyString_throwsParameterException() {
void testValidate_sillyString_throwsParameterException() {
ParameterException thrown =
assertThrows(ParameterException.class, () -> instance.validate("--time", "foo"));
assertThat(thrown).hasMessageThat().contains("--time=foo not a valid");
}
@Test
public void testValidate_correctInput_doesntThrow() {
void testValidate_correctInput_doesntThrow() {
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.InjectRule;
import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/**
* Unit tests for {@link CreateGroupsAction}.
*/
@RunWith(JUnit4.class)
public class CreateGroupsActionTest {
/** Unit tests for {@link CreateGroupsAction}. */
class CreateGroupsActionTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@RegisterExtension
final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Rule
public final InjectRule inject = new InjectRule();
@RegisterExtension final InjectRule inject = new InjectRule();
private final DirectoryGroupsConnection connection = mock(DirectoryGroupsConnection.class);
private final Response response = mock(Response.class);
@ -60,7 +54,7 @@ public class CreateGroupsActionTest {
}
@Test
public void test_invalidRequest_missingClientId() {
void test_invalidRequest_missingClientId() {
BadRequestException thrown = assertThrows(BadRequestException.class, () -> runAction(null));
assertThat(thrown)
.hasMessageThat()
@ -68,7 +62,7 @@ public class CreateGroupsActionTest {
}
@Test
public void test_invalidRequest_invalidClientId() {
void test_invalidRequest_invalidClientId() {
BadRequestException thrown =
assertThrows(BadRequestException.class, () -> runAction("completelyMadeUpClientId"));
assertThat(thrown)
@ -79,7 +73,7 @@ public class CreateGroupsActionTest {
}
@Test
public void test_createsAllGroupsSuccessfully() throws Exception {
void test_createsAllGroupsSuccessfully() throws Exception {
runAction("NewRegistrar");
verify(response).setStatus(SC_OK);
verify(response).setPayload("Success!");
@ -90,7 +84,7 @@ public class CreateGroupsActionTest {
}
@Test
public void test_createsSomeGroupsSuccessfully_whenOthersFail() throws Exception {
void test_createsSomeGroupsSuccessfully_whenOthersFail() throws Exception {
when(connection.createGroup("newregistrar-primary-contacts@domain-registry.example"))
.thenThrow(new RuntimeException("Could not contact server."));
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.FakeJsonResponse;
import org.joda.money.Money;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/**
* Unit tests for {@link CreatePremiumListAction}.
*/
@RunWith(JUnit4.class)
public class CreatePremiumListActionTest {
@Rule
@RegisterExtension
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
CreatePremiumListAction action;
FakeJsonResponse response;
private CreatePremiumListAction action;
private FakeJsonResponse response;
@Before
public void init() {
@BeforeEach
void beforeEach() {
createTlds("foo", "xn--q9jyb4c", "how");
deletePremiumList(PremiumList.getUncached("foo").get());
action = new CreatePremiumListAction();
@ -55,14 +52,14 @@ public class CreatePremiumListActionTest {
}
@Test
public void test_invalidRequest_missingInput_returnsErrorStatus() {
void test_invalidRequest_missingInput_returnsErrorStatus() {
action.name = "foo";
action.run();
assertThat(response.getResponseMap().get("status")).isEqualTo("error");
}
@Test
public void test_invalidRequest_listAlreadyExists_returnsErrorStatus() {
void test_invalidRequest_listAlreadyExists_returnsErrorStatus() {
action.name = "how";
action.inputData = "richer,JPY 5000";
action.run();
@ -74,7 +71,7 @@ public class CreatePremiumListActionTest {
}
@Test
public void test_nonExistentTld_successWithOverride() {
void test_nonExistentTld_successWithOverride() {
action.name = "zanzibar";
action.inputData = "zanzibar,USD 100";
action.override = true;
@ -84,7 +81,7 @@ public class CreatePremiumListActionTest {
}
@Test
public void test_success() {
void test_success() {
action.name = "foo";
action.inputData = "rich,USD 25\nricher,USD 1000\n";
action.run();

View file

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

View file

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

View file

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

View file

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

View file

@ -20,21 +20,16 @@ import static google.registry.testing.DatastoreHelper.persistResource;
import com.google.common.collect.ImmutableSet;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Unit tests for {@link ListRegistrarsAction}.
*/
@RunWith(JUnit4.class)
public class ListRegistrarsActionTest extends ListActionTestCase {
/** Unit tests for {@link ListRegistrarsAction}. */
class ListRegistrarsActionTest extends ListActionTestCase {
ListRegistrarsAction action;
private ListRegistrarsAction action;
@Before
public void init() {
@BeforeEach
void beforeEach() {
action = new ListRegistrarsAction();
createTlds("xn--q9jyb4c", "example");
// 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
public void testRun_noParameters() {
void testRun_noParameters() {
testRunSuccess(
action,
Optional.empty(),
@ -63,7 +58,7 @@ public class ListRegistrarsActionTest extends ListActionTestCase {
}
@Test
public void testRun_withParameters() {
void testRun_withParameters() {
testRunSuccess(
action,
Optional.of("allowedTlds"),
@ -76,7 +71,7 @@ public class ListRegistrarsActionTest extends ListActionTestCase {
}
@Test
public void testRun_withWildcard() {
void testRun_withWildcard() {
testRunSuccess(
action,
Optional.of("*"),
@ -89,7 +84,7 @@ public class ListRegistrarsActionTest extends ListActionTestCase {
}
@Test
public void testRun_withBadField_returnsError() {
void testRun_withBadField_returnsError() {
testRunError(
action,
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.label.ReservedList;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Unit tests for {@link ListReservedListsAction}.
*/
@RunWith(JUnit4.class)
public class ListReservedListsActionTest extends ListActionTestCase {
/** Unit tests for {@link ListReservedListsAction}. */
class ListReservedListsActionTest extends ListActionTestCase {
ListReservedListsAction action;
private ListReservedListsAction action;
@Before
public void init() {
@BeforeEach
void beforeEach() {
ReservedList rl1 = persistReservedList("xn--q9jyb4c-published", true, "blah,FULLY_BLOCKED");
ReservedList rl2 = persistReservedList("xn--q9jyb4c-private", false, "dugong,FULLY_BLOCKED");
createTld("xn--q9jyb4c");
@ -44,7 +39,7 @@ public class ListReservedListsActionTest extends ListActionTestCase {
}
@Test
public void testRun_noParameters() {
void testRun_noParameters() {
testRunSuccess(
action,
Optional.empty(),
@ -55,7 +50,7 @@ public class ListReservedListsActionTest extends ListActionTestCase {
}
@Test
public void testRun_withParameters() {
void testRun_withParameters() {
testRunSuccess(
action,
Optional.of("shouldPublish"),
@ -68,7 +63,7 @@ public class ListReservedListsActionTest extends ListActionTestCase {
}
@Test
public void testRun_withWildcard() {
void testRun_withWildcard() {
testRunSuccess(
action,
Optional.of("*"),
@ -81,7 +76,7 @@ public class ListReservedListsActionTest extends ListActionTestCase {
}
@Test
public void testRun_withBadField_returnsError() {
void testRun_withBadField_returnsError() {
testRunError(
action,
Optional.of("badfield"),

View file

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

View file

@ -32,24 +32,21 @@ import google.registry.testing.DatastoreHelper;
import google.registry.testing.FakeJsonResponse;
import java.math.BigDecimal;
import org.joda.money.Money;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link UpdatePremiumListAction}. */
@RunWith(JUnit4.class)
public class UpdatePremiumListActionTest {
class UpdatePremiumListActionTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@RegisterExtension
final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
UpdatePremiumListAction action;
FakeJsonResponse response;
private UpdatePremiumListAction action;
private FakeJsonResponse response;
@Before
public void init() {
@BeforeEach
void beforeEach() {
createTlds("foo", "xn--q9jyb4c", "how");
action = new UpdatePremiumListAction();
response = new FakeJsonResponse();
@ -57,14 +54,14 @@ public class UpdatePremiumListActionTest {
}
@Test
public void test_invalidRequest_missingInput_returnsErrorStatus() {
void test_invalidRequest_missingInput_returnsErrorStatus() {
action.name = "foo";
action.run();
assertThat(response.getResponseMap().get("status")).isEqualTo("error");
}
@Test
public void test_invalidRequest_listDoesNotExist_returnsErrorStatus() {
void test_invalidRequest_listDoesNotExist_returnsErrorStatus() {
action.name = "bamboozle";
action.inputData = "richer,JPY 5000";
action.run();
@ -76,7 +73,7 @@ public class UpdatePremiumListActionTest {
}
@Test
public void test_success() {
void test_success() {
PremiumListDao.saveNew(
parseToPremiumList(
"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 java.util.Map;
import java.util.regex.Pattern;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link VerifyOteAction}. */
@RunWith(JUnit4.class)
public class VerifyOteActionTest {
class VerifyOteActionTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@RegisterExtension
final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private final VerifyOteAction action = new VerifyOteAction();
@Test
public void testSuccess_summarize_allPass() throws Exception {
void testSuccess_summarize_allPass() throws Exception {
OteStatsTestHelper.setupCompleteOte("blobio");
assertThat(getResponse(true))
.isEqualTo("# actions: 30 - Reqs: [----------------] 16/16 - Overall: PASS");
}
@Test
public void testFailure_summarize_someFailures() throws Exception {
void testFailure_summarize_someFailures() throws Exception {
OteStatsTestHelper.setupIncompleteOte("blobio");
assertThat(getResponse(true))
.isEqualTo("# actions: 34 - Reqs: [-.-----.------.-] 13/16 - Overall: FAIL");
}
@Test
public void testSuccess_passNotSummarized() throws Exception {
void testSuccess_passNotSummarized() throws Exception {
OteStatsTestHelper.setupCompleteOte("blobio");
String expectedOteStatus =
"domain creates idn: 1\n"
@ -81,7 +78,7 @@ public class VerifyOteActionTest {
}
@Test
public void testFailure_incomplete() throws Exception {
void testFailure_incomplete() throws Exception {
OteStatsTestHelper.setupIncompleteOte("blobio");
String expectedOteStatus =
"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.setUpSslChannel;
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 google.registry.networking.util.SelfSignedCaCertificate;
@ -225,7 +225,7 @@ public class SslClientInitializerTest {
sslProvider, hostProvider, portProvider, ImmutableList.of(ssc.cert()), null, null);
nettyRule.setUpClient(localAddress, sslClientInitializer);
verifySslExcpetion(
verifySslException(
nettyRule.getClientChannel(),
channel -> channel.pipeline().get(SslHandler.class).handshakeFuture().get(),
CertificateExpiredException.class);
@ -259,7 +259,7 @@ public class SslClientInitializerTest {
sslProvider, hostProvider, portProvider, ImmutableList.of(ssc.cert()), null, null);
nettyRule.setUpClient(localAddress, sslClientInitializer);
verifySslExcpetion(
verifySslException(
nettyRule.getClientChannel(),
channel -> channel.pipeline().get(SslHandler.class).handshakeFuture().get(),
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. */
static void verifySslExcpetion(
static void verifySslException(
Channel channel, CheckedConsumer<Channel> operation, Class<? extends Exception> cause)
throws Exception {
// 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.setUpSslChannel;
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 com.google.common.base.Suppliers;
@ -181,7 +181,7 @@ public class SslServerInitializerTest {
nettyRule.setUpClient(
localAddress, getClientHandler(serverSsc.cert(), clientSsc.key(), clientSsc.cert()));
verifySslExcpetion(
verifySslException(
nettyRule.getServerChannel(),
channel -> channel.attr(CLIENT_CERTIFICATE_PROMISE_KEY).get().get(),
CertificateExpiredException.class);
@ -202,7 +202,7 @@ public class SslServerInitializerTest {
nettyRule.setUpClient(
localAddress, getClientHandler(serverSsc.cert(), clientSsc.key(), clientSsc.cert()));
verifySslExcpetion(
verifySslException(
nettyRule.getServerChannel(),
channel -> channel.attr(CLIENT_CERTIFICATE_PROMISE_KEY).get().get(),
CertificateNotYetValidException.class);