### Question:
AttributeService { public Object getAttribute(File file, String attribute) { String view = getViewName(attribute); String attr = getSingleAttribute(attribute); return getAttribute(file, view, attr); } AttributeService(Configuration configuration);  AttributeService(
      Iterable<? extends AttributeProvider> providers, Map<String, ?> userProvidedDefaults); ImmutableSet<String> supportedFileAttributeViews(); boolean supportsFileAttributeView(Class<? extends FileAttributeView> type); void setInitialAttributes(File file, FileAttribute<?>... attrs); void copyAttributes(File file, File copy, AttributeCopyOption copyOption); Object getAttribute(File file, String attribute); Object getAttribute(File file, String view, String attribute); void setAttribute(File file, String attribute, Object value, boolean create); @SuppressWarnings("unchecked") @NullableDecl V getFileAttributeView(FileLookup lookup, Class<V> type); ImmutableMap<String, Object> readAttributes(File file, String attributes); @SuppressWarnings("unchecked") A readAttributes(File file, Class<A> type);  }### Answer:
@Test public void testGetAttribute() { File file = Directory.create(0); service.setInitialAttributes(file); assertThat(service.getAttribute(file, "test:foo")).isEqualTo("hello"); assertThat(service.getAttribute(file, "test", "foo")).isEqualTo("hello"); assertThat(service.getAttribute(file, "basic:isRegularFile")).isEqualTo(false); assertThat(service.getAttribute(file, "isDirectory")).isEqualTo(true); assertThat(service.getAttribute(file, "test:baz")).isEqualTo(1); }
@Test public void testGetAttribute_fromInheritedProvider() { File file = Directory.create(0); assertThat(service.getAttribute(file, "test:isRegularFile")).isEqualTo(false); assertThat(service.getAttribute(file, "test:isDirectory")).isEqualTo(true); assertThat(service.getAttribute(file, "test", "fileKey")).isEqualTo(0); }
@Test public void testGetAttribute_failsForAttributesNotDefinedByProvider() { File file = Directory.create(0); try { service.getAttribute(file, "test:blah"); fail(); } catch (IllegalArgumentException expected) { } try { service.getAttribute(file, "basic", "baz"); fail(); } catch (IllegalArgumentException expected) { } }
@Test public void testIllegalAttributeFormats() { File file = Directory.create(0); try { service.getAttribute(file, ":bar"); fail(); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage()).contains("attribute format"); } try { service.getAttribute(file, "test:"); fail(); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage()).contains("attribute format"); } try { service.getAttribute(file, "basic:test:isDirectory"); fail(); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage()).contains("attribute format"); } try { service.getAttribute(file, "basic:fileKey,size"); fail(); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage()).contains("single attribute"); } }