mirror of https://github.com/apache/jclouds.git
Small cleanup of how RegionToEndpoint checks arguments.
This commit is contained in:
parent
8a322c42e6
commit
ca58491ce8
|
@ -26,7 +26,6 @@ import java.util.Map;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
|
||||||
import org.jclouds.location.Region;
|
import org.jclouds.location.Region;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -47,8 +46,7 @@ public class RegionToEndpoint implements Function<Object, URI> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI apply(@Nullable Object from) {
|
public URI apply(Object from) {
|
||||||
checkArgument(from != null && from instanceof String, "you must specify a region, as a String argument");
|
|
||||||
Map<String, Supplier<URI>> regionToEndpoint = regionToEndpointSupplier.get();
|
Map<String, Supplier<URI>> regionToEndpoint = regionToEndpointSupplier.get();
|
||||||
checkState(regionToEndpoint.size() > 0, "no region name to endpoint mappings configured!");
|
checkState(regionToEndpoint.size() > 0, "no region name to endpoint mappings configured!");
|
||||||
checkArgument(regionToEndpoint.containsKey(from),
|
checkArgument(regionToEndpoint.containsKey(from),
|
||||||
|
|
|
@ -18,7 +18,6 @@ package org.jclouds.location.functions;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -43,24 +42,10 @@ public class RegionToEndpointTest {
|
||||||
assertEquals(fn.apply("1"), URI.create("http://1"));
|
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)
|
@Test(expectedExceptions = IllegalStateException.class)
|
||||||
public void testMustHaveEndpoints() {
|
public void testMustHaveEndpoints() {
|
||||||
RegionToEndpoint fn = new RegionToEndpoint(Suppliers.<Map<String, Supplier<URI>>> ofInstance(ImmutableMap
|
RegionToEndpoint fn = new RegionToEndpoint(Suppliers.<Map<String, Supplier<URI>>> ofInstance(ImmutableMap
|
||||||
.<String, Supplier<URI>> of()));
|
.<String, Supplier<URI>> of()));
|
||||||
fn.apply("1");
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue