### Question:
GlusterDirectoryStream implements DirectoryStream<Path> { public void open(GlusterPath path) { dir = path; if (dirHandle == 0) { dirHandle = GLFS.glfs_opendir(path.getFileSystem().getVolptr(), path.getString()); } else { throw new IllegalStateException("Already open!"); } }  @Override Iterator<Path> iterator(); @Override void close(); void open(GlusterPath path);  }### Answer:
@Test(expected = IllegalStateException.class) public void testOpenDirectory_whenAlreadyOpen() { stream.setDirHandle(1); stream.open(mockPath); }
@Test public void testOpenDirectory() { String fakePath = "/foo/baz"; doReturn(mockFileSystem).when(mockPath).getFileSystem(); doReturn(fsHandle).when(mockFileSystem).getVolptr(); doReturn(fakePath).when(mockPath).getString(); mockStatic(GLFS.class); when(GLFS.glfs_opendir(fsHandle, fakePath)).thenReturn(dirHandle); stream.open(mockPath); assertEquals(dirHandle, stream.getDirHandle()); assertEquals(false, stream.isClosed()); assertEquals(mockPath, stream.getDir()); verify(mockPath).getFileSystem(); verify(mockFileSystem).getVolptr(); verify(mockPath).getString(); verifyStatic(); GLFS.glfs_opendir(fsHandle, fakePath); }