@Test
  public void testView() throws IOException {
    UserDefinedFileAttributeView view = provider.view(fileLookup(), NO_INHERITED_VIEWS);
    assertNotNull(view);

    assertThat(view.name()).isEqualTo("user");
    assertThat(view.list()).isEmpty();

    byte[] b1 = {0, 1, 2};
    byte[] b2 = {0, 1, 2, 3, 4};

    view.write("b1", ByteBuffer.wrap(b1));
    view.write("b2", ByteBuffer.wrap(b2));

    assertThat(view.list()).containsAtLeast("b1", "b2");
    assertThat(file.getAttributeKeys()).containsExactly("user:b1", "user:b2");

    assertThat(view.size("b1")).isEqualTo(3);
    assertThat(view.size("b2")).isEqualTo(5);

    ByteBuffer buf1 = ByteBuffer.allocate(view.size("b1"));
    ByteBuffer buf2 = ByteBuffer.allocate(view.size("b2"));

    view.read("b1", buf1);
    view.read("b2", buf2);

    assertThat(Arrays.equals(b1, buf1.array())).isTrue();
    assertThat(Arrays.equals(b2, buf2.array())).isTrue();

    view.delete("b2");

    assertThat(view.list()).containsExactly("b1");
    assertThat(file.getAttributeKeys()).containsExactly("user:b1");

    try {
      view.size("b2");
      fail();
    } catch (IllegalArgumentException expected) {
      assertThat(expected.getMessage()).contains("not set");
    }

    try {
      view.read("b2", ByteBuffer.allocate(10));
      fail();
    } catch (IllegalArgumentException expected) {
      assertThat(expected.getMessage()).contains("not set");
    }

    view.write("b1", ByteBuffer.wrap(b2));
    assertThat(view.size("b1")).isEqualTo(5);

    view.delete("b2"); // succeeds
  }
Tests for {@link UserDefinedAttributeProvider}.

@author Colin Decker
jimfs/src/test/java/com/google/common/jimfs/UserDefinedAttributeProviderTest.java