diff --git a/javatests/google/registry/monitoring/metrics/CounterTest.java b/javatests/google/registry/monitoring/metrics/CounterTest.java index a57019413..a1b8d3e1f 100644 --- a/javatests/google/registry/monitoring/metrics/CounterTest.java +++ b/javatests/google/registry/monitoring/metrics/CounterTest.java @@ -15,7 +15,6 @@ package google.registry.monitoring.metrics; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -123,12 +122,9 @@ public class CounterTest { "vdn", ImmutableSet.of(LabelDescriptor.create("label1", "bar"))); - try { - counter.incrementBy(-1L, "foo"); - fail("Test should not allow non-negative offsets"); - } catch (IllegalArgumentException expected) { - assertThat(expected).hasMessage("The offset provided must be non-negative"); - } + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage("The offset provided must be non-negative"); + counter.incrementBy(-1L, "foo"); } @Test diff --git a/javatests/google/registry/tools/MutatingCommandTest.java b/javatests/google/registry/tools/MutatingCommandTest.java index ab735a69b..107506356 100644 --- a/javatests/google/registry/tools/MutatingCommandTest.java +++ b/javatests/google/registry/tools/MutatingCommandTest.java @@ -15,13 +15,13 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; -import static com.google.common.truth.Truth.assertWithMessage; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistResource; import static org.joda.time.DateTimeZone.UTC; +import static org.junit.Assert.fail; import google.registry.model.host.HostResource; import google.registry.model.registrar.Registrar; @@ -285,6 +285,7 @@ public class MutatingCommandTest { + "blockPremiumNames -> [false, true]\n"); try { command.execute(); + fail("Expected transaction to fail with IllegalStateException."); } catch (IllegalStateException e) { assertThat(e.getMessage()).contains("Entity changed since init() was called."); assertThat(ofy().load().entity(host1).now()).isNull(); @@ -293,9 +294,7 @@ public class MutatingCommandTest { // These two shouldn't've changed. assertThat(ofy().load().entity(registrar1).now()).isEqualTo(registrar1); assertThat(ofy().load().entity(registrar2).now()).isEqualTo(registrar2); - return; } - assertWithMessage("Expected transaction to fail with IllegalStateException").fail(); } @Test diff --git a/javatests/google/registry/tools/UpdateApplicationStatusCommandTest.java b/javatests/google/registry/tools/UpdateApplicationStatusCommandTest.java index 361284d20..f26d68e8b 100644 --- a/javatests/google/registry/tools/UpdateApplicationStatusCommandTest.java +++ b/javatests/google/registry/tools/UpdateApplicationStatusCommandTest.java @@ -16,7 +16,6 @@ package google.registry.tools; import static com.google.common.collect.Iterables.getLast; import static com.google.common.truth.Truth.assertThat; -import static com.google.common.truth.Truth.assert_; import static google.registry.model.domain.launch.ApplicationStatus.ALLOCATED; import static google.registry.model.domain.launch.ApplicationStatus.PENDING_ALLOCATION; import static google.registry.model.domain.launch.ApplicationStatus.REJECTED; @@ -28,6 +27,7 @@ import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static org.joda.time.DateTimeZone.UTC; +import static org.junit.Assert.fail; import com.google.common.collect.FluentIterable; import google.registry.model.domain.DomainApplication; @@ -256,6 +256,7 @@ public class UpdateApplicationStatusCommandTest try { runCommandForced("--ids=2-Q9JYB4C", "--msg=\"Application rejected\"", "--status=REJECTED"); + fail("Expected IllegalStateException \"Domain application has final status ALLOCATED\""); } catch (IllegalStateException e) { assertThat(e.getMessage()).contains("Domain application has final status ALLOCATED"); assertAboutApplications().that(ofy().load().entity(domainApplication).now()) @@ -263,10 +264,7 @@ public class UpdateApplicationStatusCommandTest assertThat(getPollMessageCount()).isEqualTo(0); assertAboutHistoryEntries().that(loadLastHistoryEntry()) .hasType(HistoryEntry.Type.DOMAIN_APPLICATION_CREATE); - return; } - assert_().fail( - "Expected IllegalStateException \"Domain application has final status ALLOCATED\""); } @Test diff --git a/javatests/google/registry/tools/server/CreateGroupsActionTest.java b/javatests/google/registry/tools/server/CreateGroupsActionTest.java index 8da21c953..645488973 100644 --- a/javatests/google/registry/tools/server/CreateGroupsActionTest.java +++ b/javatests/google/registry/tools/server/CreateGroupsActionTest.java @@ -16,6 +16,7 @@ package google.registry.tools.server; import static com.google.common.truth.Truth.assertThat; import static javax.servlet.http.HttpServletResponse.SC_OK; +import static org.junit.Assert.fail; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -29,7 +30,6 @@ import google.registry.request.Response; import google.registry.testing.AppEngineRule; import google.registry.testing.ExceptionRule; import google.registry.testing.InjectRule; -import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -103,6 +103,7 @@ public class CreateGroupsActionTest { Role.MEMBER); try { runAction("NewRegistrar"); + fail("Should have thrown InternalServerErrorException."); } catch (InternalServerErrorException e) { String responseString = e.toString(); assertThat(responseString).contains("abuse => Success"); @@ -115,9 +116,7 @@ public class CreateGroupsActionTest { assertThat(responseString).contains( "technical => java.lang.RuntimeException: Invalid access."); verifyGroupCreationCallsForNewRegistrar(); - return; } - Assert.fail("Should have thrown InternalServerErrorException."); } private void verifyGroupCreationCallsForNewRegistrar() throws Exception { diff --git a/javatests/google/registry/whois/WhoisServerTest.java b/javatests/google/registry/whois/WhoisServerTest.java index 7650f959b..ac6abac1d 100644 --- a/javatests/google/registry/whois/WhoisServerTest.java +++ b/javatests/google/registry/whois/WhoisServerTest.java @@ -17,6 +17,7 @@ package google.registry.whois; import static com.google.common.truth.Truth.assertThat; import static google.registry.model.registrar.Registrar.State.ACTIVE; import static google.registry.model.registrar.Registrar.Type.PDT; +import static google.registry.model.registry.Registries.getTlds; import static google.registry.testing.DatastoreHelper.createTlds; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistSimpleResources; @@ -26,13 +27,11 @@ import static google.registry.testing.FullFieldsTestEntityHelper.makeHostResourc import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrar; import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrarContacts; import static google.registry.whois.WhoisHelper.loadWhoisTestFile; -import static org.junit.Assert.fail; import google.registry.model.domain.DomainResource; import google.registry.model.ofy.Ofy; import google.registry.model.registrar.Registrar; import google.registry.model.registry.Registry; -import google.registry.model.registry.Registry.RegistryNotFoundException; import google.registry.testing.AppEngineRule; import google.registry.testing.FakeClock; import google.registry.testing.FakeResponse; @@ -325,12 +324,7 @@ public class WhoisServerTest { @Test public void testRun_ipMapsToNameserverUnderNonAuthoritativeTld_notFound() throws Exception { - try { - Registry.get("com"); - fail("Found Registry when none should exist"); - } catch (RegistryNotFoundException e) { - // expected - } + assertThat(getTlds()).doesNotContain("com"); persistResource(makeHostResource("ns1.google.com", "1.2.3.4")); newWhoisServer("nameserver 1.2.3.4").run(); assertThat(response.getStatus()).isEqualTo(200); @@ -339,12 +333,7 @@ public class WhoisServerTest { @Test public void testRun_nameserverUnderNonAuthoritativeTld_notFound() throws Exception { - try { - Registry.get("com"); - fail("Found Registry when none should exist"); - } catch (RegistryNotFoundException e) { - // expected - } + assertThat(getTlds()).doesNotContain("com"); persistResource(makeHostResource("ns1.google.com", "1.2.3.4")); newWhoisServer("nameserver ns1.google.com").run(); assertThat(response.getStatus()).isEqualTo(200);