VFSServicesServerImpl implements VFSService { @Override public DirectoryStream<Path> newDirectoryStream(final Path dir) throws IllegalArgumentException, NotDirectoryException, IOException { final Iterator<org.uberfire.java.nio.file.Path> content = ioService.newDirectoryStream(Paths.convert(dir)).iterator(); return newDirectoryStream(content); } protected  VFSServicesServerImpl(); @Inject  VFSServicesServerImpl(final @Named("ioStrategy") IOService ioService); @Override Path get(final String uri); @Override DirectoryStream<Path> newDirectoryStream(final Path dir); @Override DirectoryStream<Path> newDirectoryStream(final Path dir,
                                                    final DirectoryStream.Filter<Path> filter); @Override Path createDirectory(final Path dir); @Override Path createDirectories(final Path dir); @Override Path createDirectory(final Path dir,
                                final Map<String, ?> attrs); @Override Path createDirectories(final Path dir,
                                  final Map<String, ?> attrs); @Override Map<String, Object> readAttributes(final Path path); @Override void setAttributes(final Path path,
                              final Map<String, Object> attrs); @Override void delete(final Path path); @Override boolean deleteIfExists(final Path path); @Override Path copy(final Path source,
                     final Path target); @Override Path move(final Path source,
                     final Path target); @Override String readAllString(final Path path); @Override Path write(final Path path,
                      final String content); @Override Path write(final Path path,
                      final String content,
                      final Map<String, ?> attrs); @Override boolean isRegularFile(final String uri); @Override boolean isRegularFile(final Path path); @Override boolean isDirectory(final String uri); @Override boolean isDirectory(final Path path);  }
@Test public void testNewDirectoryStream() { doAnswer((Answer<org.uberfire.java.nio.file.DirectoryStream<org.uberfire.java.nio.file.Path>>) invocationOnMock -> rootDirectoryStream) .when(ioService) .newDirectoryStream(any(org.uberfire.java.nio.file.Path.class)); final DirectoryStream<Path> paths = tested.newDirectoryStream(ROOT_PATH); final Path path = paths.iterator().next(); assertEquals(ROOT_PATH, path); }
@Test @SuppressWarnings("unchecked") public void testNewDirectoryStreamFiltered() { final DirectoryStream.Filter<Path> filter = mock(DirectoryStream.Filter.class); doAnswer((Answer<org.uberfire.java.nio.file.DirectoryStream<org.uberfire.java.nio.file.Path>>) invocationOnMock -> { org.uberfire.java.nio.file.DirectoryStream.Filter<org.uberfire.java.nio.file.Path> argFilter = (org.uberfire.java.nio.file.DirectoryStream.Filter<org.uberfire.java.nio.file.Path>) invocationOnMock.getArguments()[1]; argFilter.accept(rootPath); return rootDirectoryStream; }) .when(ioService) .newDirectoryStream(any(org.uberfire.java.nio.file.Path.class), any(org.uberfire.java.nio.file.DirectoryStream.Filter.class)); final DirectoryStream<Path> paths = tested.newDirectoryStream(ROOT_PATH, filter); verify(filter, times(1)).accept(eq(ROOT_PATH)); final Path path = paths.iterator().next(); assertEquals(ROOT_PATH, path); }