JCLOUDS-401. Make BlobName Function type-safe

This commit is contained in:
Andrew Gaul 2013-06-18 21:17:09 -07:00
parent ac06e32e72
commit d25e972344
2 changed files with 3 additions and 11 deletions

View File

@ -16,7 +16,6 @@
*/
package org.jclouds.blobstore.functions;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton;
@ -30,12 +29,10 @@ import com.google.common.base.Function;
* @author Adrian Cole
*/
@Singleton
public class BlobName implements Function<Object, String> {
public final class BlobName implements Function<Blob, String> {
public String apply(Object input) {
checkArgument(checkNotNull(input, "input") instanceof Blob, "this function is only valid for Blobs!");
return checkNotNull(Blob.class.cast(input).getMetadata().getName(), "blobName");
public String apply(Blob input) {
return checkNotNull(checkNotNull(input, "input").getMetadata().getName(), "blobName");
}
}

View File

@ -44,11 +44,6 @@ public class BlobNameTest {
assertEquals(fn.apply(blob), "foo");
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testMustBeBlob() {
fn.apply(new File("foo"));
}
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class })
public void testNullIsBad() {
fn.apply(null);