AtmosObjectName implements Function<Object, String> { @Override public String apply(Object input) { checkArgument(checkNotNull(input, "input") instanceof AtmosObject, "this function is only valid for AtmosObjects!"); AtmosObject object = AtmosObject.class.cast(input); return checkNotNull(object.getContentMetadata().getName() != null ? object.getContentMetadata().getName() : object.getSystemMetadata().getObjectName(), "objectName"); }  @Override String apply(Object input);  }
@Test public void testCorrectContentMetadataName() throws SecurityException, NoSuchMethodException { AtmosObject blob = BLOB_FACTORY.create(null); blob.getContentMetadata().setName("foo"); assertEquals(fn.apply(blob), "foo"); }
@Test public void testCorrectSystemMetadataObjectName() throws SecurityException, NoSuchMethodException { AtmosObject blob = BLOB_FACTORY.create(new SystemMetadata(null, null, null, null, null, null, 0, null, "foo", null, 0, null, null), new UserMetadata()); assertEquals(fn.apply(blob), "foo"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testMustBeAtmosObject() { fn.apply(new File("foo")); }
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class }) public void testNullIsBad() { fn.apply(null); }