mirror of
https://github.com/google/nomulus
synced 2026-02-11 07:11:40 +00:00
Make Registrar load methods return Optionals instead of Nullables
This makes the code more understandable from callsites, and also forces users of this function to deal with the situation where the registrar with a given client ID might not be present (it was previously silently NPEing from some of the callsites). This also adds a test helper method loadRegistrar(clientId) that retains the old functionality for terseness in tests. It also fixes some instances of using the load method with the wrong cachedness -- some uses in high- traffic situations (WHOIS) that should have caching, but also low-traffic reporting that don't benefit from caching so might as well always be current. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=162990468
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
package google.registry.tools;
|
||||
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static org.mockito.Matchers.anyMapOf;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
@@ -21,7 +22,6 @@ import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.common.base.VerifyException;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
@@ -48,7 +48,7 @@ public class VerifyOteCommandTest extends CommandTestCase<VerifyOteCommand> {
|
||||
@Test
|
||||
public void testSuccess_pass() throws Exception {
|
||||
Registrar registrar =
|
||||
Registrar.loadByClientId("TheRegistrar")
|
||||
loadRegistrar("TheRegistrar")
|
||||
.asBuilder()
|
||||
.setClientId("blobio-1")
|
||||
.setRegistrarName("blobio-1")
|
||||
@@ -66,7 +66,7 @@ public class VerifyOteCommandTest extends CommandTestCase<VerifyOteCommand> {
|
||||
|
||||
@Test
|
||||
public void testFailure_registrarDoesntExist() throws Exception {
|
||||
thrown.expect(VerifyException.class, "Registrar blobio does not exist.");
|
||||
thrown.expect(IllegalArgumentException.class, "Registrar blobio does not exist.");
|
||||
runCommand("blobio");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user