fsProvider.move( null, null );
}
@Test
public void checkNewDirectoryStream() throws IOException {
final SimpleFileSystemProvider fsProvider = new SimpleFileSystemProvider();
final String userSourcePath = System.getProperty( "user.dir" ) + "/temp";
final Path dir = GeneralPathImpl.create( fsProvider.getFileSystem( URI.create( "file:///" ) ), userSourcePath, false );
FileUtils.deleteDirectory( dir.toFile() );
fsProvider.createDirectory( dir );
final DirectoryStream<Path> stream = fsProvider.newDirectoryStream( dir, new DirectoryStream.Filter<Path>() {
@Override
public boolean accept( Path entry ) throws org.uberfire.java.nio.IOException {
return true;
}
} );
assertThat( stream ).hasSize( 0 );
try {
stream.iterator().next();
fail( "can't navigate to next on empty iterator" );
} catch ( NoSuchElementException ex ) {
}
final File tempFile = File.createTempFile( "foo", "bar", dir.toFile() );
final Path path = GeneralPathImpl.newFromFile( fsProvider.getFileSystem( URI.create( "file:///" ) ), tempFile );
final DirectoryStream<Path> stream2 = fsProvider.newDirectoryStream( dir, new DirectoryStream.Filter<Path>() {
@Override
public boolean accept( Path entry ) throws org.uberfire.java.nio.IOException {
return true;
}
} );
assertThat( stream2 ).hasSize( 1 );
final Iterator<Path> iterator = stream2.iterator();
iterator.next();
try {
iterator.remove();
fail( "can't remove elements" );
} catch ( UnsupportedOperationException ex ) {
}
stream2.close();
try {
stream2.close();
fail( "stram already closed" );
} catch ( Exception ex ) {
}
final File tempFile2 = File.createTempFile( "bar", "foo", dir.toFile() );
final Path path2 = GeneralPathImpl.newFromFile( fsProvider.getFileSystem( URI.create( "file:///" ) ), tempFile2 );
final DirectoryStream<Path> stream3 = fsProvider.newDirectoryStream( dir, new DirectoryStream.Filter<Path>() {
@Override
public boolean accept( Path entry ) throws org.uberfire.java.nio.IOException {
return true;
}
} );
assertThat( stream3 ).hasSize( 2 ).contains( path, path2 );
stream3.close();
try {
stream3.iterator().next();
fail( "can't interact in an already closed stream" );
} catch ( Exception ex ) {
}
final DirectoryStream<Path> stream4 = fsProvider.newDirectoryStream( dir, new DirectoryStream.Filter<Path>() {
@Override
public boolean accept( final Path entry ) throws org.uberfire.java.nio.IOException {
if ( entry.getFileName().toString().startsWith( "foo" ) ) {
return true;
}