Small cleanup of how RegionToEndpoint checks arguments.

This commit is contained in:
Zack Shoylev 2014-11-12 08:36:50 -06:00 committed by Adrian Cole
parent dedeb63b0f
commit a9fa05577e
2 changed files with 1 additions and 18 deletions

View File

@ -26,7 +26,6 @@ import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region;
import com.google.common.base.Function;
@ -43,8 +42,7 @@ public class RegionToEndpoint implements Function<Object, URI> {
}
@Override
public URI apply(@Nullable Object from) {
checkArgument(from != null && from instanceof String, "you must specify a region, as a String argument");
public URI apply(Object from) {
Map<String, Supplier<URI>> regionToEndpoint = regionToEndpointSupplier.get();
checkState(regionToEndpoint.size() > 0, "no region name to endpoint mappings configured!");
checkArgument(regionToEndpoint.containsKey(from),

View File

@ -18,7 +18,6 @@ package org.jclouds.location.functions;
import static org.testng.Assert.assertEquals;
import java.io.File;
import java.net.URI;
import java.util.Map;
@ -41,24 +40,10 @@ public class RegionToEndpointTest {
assertEquals(fn.apply("1"), URI.create("http://1"));
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testMustBeString() {
RegionToEndpoint fn = new RegionToEndpoint(Suppliers.<Map<String, Supplier<URI>>> ofInstance(ImmutableMap.of("1",
Suppliers.ofInstance(URI.create("http://1")))));
fn.apply(new File("foo"));
}
@Test(expectedExceptions = IllegalStateException.class)
public void testMustHaveEndpoints() {
RegionToEndpoint fn = new RegionToEndpoint(Suppliers.<Map<String, Supplier<URI>>> ofInstance(ImmutableMap
.<String, Supplier<URI>> of()));
fn.apply("1");
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNullIsIllegal() {
RegionToEndpoint fn = new RegionToEndpoint(Suppliers.<Map<String, Supplier<URI>>> ofInstance(ImmutableMap.of("1",
Suppliers.ofInstance(URI.create("http://1")))));
fn.apply(null);
}
}