mirror of
https://github.com/apache/jclouds.git
synced 2025-02-09 11:35:41 +00:00
JCLOUDS-401. Make BlobName Function type-safe
This commit is contained in:
parent
ac06e32e72
commit
d25e972344
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.jclouds.blobstore.functions;
|
package org.jclouds.blobstore.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@ -30,12 +29,10 @@ import com.google.common.base.Function;
|
|||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class BlobName implements Function<Object, String> {
|
public final class BlobName implements Function<Blob, String> {
|
||||||
|
|
||||||
public String apply(Object input) {
|
public String apply(Blob input) {
|
||||||
checkArgument(checkNotNull(input, "input") instanceof Blob, "this function is only valid for Blobs!");
|
return checkNotNull(checkNotNull(input, "input").getMetadata().getName(), "blobName");
|
||||||
|
|
||||||
return checkNotNull(Blob.class.cast(input).getMetadata().getName(), "blobName");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,11 +44,6 @@ public class BlobNameTest {
|
|||||||
assertEquals(fn.apply(blob), "foo");
|
assertEquals(fn.apply(blob), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
|
||||||
public void testMustBeBlob() {
|
|
||||||
fn.apply(new File("foo"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class })
|
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class })
|
||||||
public void testNullIsBad() {
|
public void testNullIsBad() {
|
||||||
fn.apply(null);
|
fn.apply(null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user