/** * Creates a new instance of <code>{@link IterableAssert}</code>. * @param actual the actual value. * @return the created assertion object. */ public static <T> IterableAssert<T> assertThat(Iterable<T> actual) { return new IterableAssert<T>(actual); }
@Test public void simpleTests() { final FileSystem fileSystem = new SimpleUnixFileSystem( fsProvider, "/" ); assertThat( fileSystem.isOpen() ).isTrue(); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( System.getProperty( "file.separator" ) ); assertThat( fileSystem.provider() ).isEqualTo( fsProvider ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 1 ).contains( "basic" ); assertThat( fileSystem.getPath( "/path/to/file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); assertThat( fileSystem.getPath( "/path/to/file.txt", null ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); assertThat( fileSystem.getPath( "/path", "to", "file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); try { fileSystem.close(); fail( "can't close this fileSystem" ); } catch ( UnsupportedOperationException ex ) { } assertThat( fileSystem.getFileStores() ).isNotNull().hasSize( 1 ); assertThat( fileSystem.getFileStores().iterator().next().name() ).isEqualTo( "/" ); assertThat( fileSystem.getRootDirectories() ).isNotNull().hasSize( 1 ); assertThat( fileSystem.getRootDirectories().iterator().next().toString() ).isEqualTo( "/" ); assertThat( fileSystem.getRootDirectories().iterator().next().isAbsolute() ).isTrue(); }
assertThat( stream1 ).isNotNull().hasSize( 2 ).contains( path3, PROVIDER.getPath( URI.create( "git://user_branch@dirstream-test-repo/other" ) ) ); assertThat( stream2 ).isNotNull().hasSize( 1 ).contains( PROVIDER.getPath( URI.create( "git://user_branch@dirstream-test-repo/other/path" ) ) ); assertThat( stream3 ).isNotNull().hasSize( 1 ).contains( path2 ); assertThat( stream4 ).isNotNull().hasSize( 1 ).contains( path ); assertThat( PROVIDER.newDirectoryStream( crazyPath, null ) ).isNotNull().hasSize( 1 );
@Test public void testNewFileSystemInited() { final URI newRepo = URI.create( "git://init-repo-name" ); final Map<String, ?> env = new HashMap<String, Object>() {{ put( "init", Boolean.TRUE ); }}; final FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); assertThat( fs ).isNotNull(); final DirectoryStream<Path> stream = PROVIDER.newDirectoryStream( PROVIDER.getPath( newRepo ), null ); assertThat( stream ).isNotNull().hasSize( 1 ); }
@Test public void testGetComplexPath() { final URI newRepo = URI.create( "git://new-complex-get-repo-name" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://origin/master@new-complex-get-repo-name/home" ) ); assertThat( path ).isNotNull(); assertThat( path.getRoot().toString() ).isEqualTo( "/" ); assertThat( path.toString() ).isEqualTo( "/home" ); final Path pathRelative = PROVIDER.getPath( URI.create( "git://origin/master@new-complex-get-repo-name/:home" ) ); assertThat( pathRelative ).isNotNull(); assertThat( pathRelative.getRoot().toString() ).isEqualTo( "" ); assertThat( pathRelative.toString() ).isEqualTo( "home" ); }
@Test public void simpleRootTests() throws URISyntaxException { final SimpleFileSystemProvider fs = new SimpleFileSystemProvider(); final FileSystem fileSystem = new SimpleUnixFileSystem( fsProvider, "/" ); assertThat( fileSystem.getPath( "/" ) ).isEqualTo( fileSystem.getPath( "/path" ).getParent() ); final URL parentUrl = this.getClass().getResource( "/" ); final Path parentNioPath = fs.getPath( parentUrl.toURI() ); final URL childUrl = this.getClass().getResource( "/Folder" ); final Path childNioPath = fs.getPath( childUrl.toURI() ); final Path childParentNioPath = childNioPath.getParent(); System.out.println( parentNioPath ); assertThat( parentNioPath ).isEqualTo( childParentNioPath ); }
@Test public void checkDeleteNonEmptyDir() 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 ); File.createTempFile( "foo", "bar", dir.toFile() ); File.createTempFile( "bar", "foo", dir.toFile() ); File.createTempFile( "bar", "foo", dir.toFile() ); fsProvider.createDirectory( dir.resolve( "other_dir" ) ); final DirectoryStream<Path> stream5 = fsProvider.newDirectoryStream( dir, new DirectoryStream.Filter<Path>() { @Override public boolean accept( final Path entry ) throws org.kie.commons.java.nio.IOException { return true; } } ); assertThat( stream5 ).hasSize( 4 ).contains( dir.resolve( "other_dir" ) ); try { fsProvider.delete( dir ); fail( "must throw error" ); } catch ( final DirectoryNotEmptyException expection ) { } fsProvider.delete( dir, NON_EMPTY_DIRECTORIES ); assertThat( dir.toFile().exists() ).isEqualTo( false ); }
@Test public void testSupportedFileAttributeViews() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final Git git = setupGit(); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( "/" ); assertThat( fileSystem.getName() ).isEqualTo( "my-repo" ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 2 ).contains( "basic", "version" ); }
@Test public void testSimpleBranchedGit() { final Path path = JGitPathImpl.create(fs, "", "master@my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/"); assertThat(path.getRoot()).isEqualTo(path); assertThat(path.getNameCount()).isEqualTo(0); assertThat(path.getRoot()).isNotNull().isEqualTo(path); }
@Test public void checkGetFileStore() { final SimpleFileSystemProvider fsProvider = new SimpleFileSystemProvider(); final Path path = GeneralPathImpl.create( fsProvider.getFileSystem( URI.create( "file:///" ) ), "/path/to/file.txt", false ); assertThat( fsProvider.getFileStore( path ) ).isNotNull(); assertThat( fsProvider.getFileSystem( path.toUri() ).getFileStores() ).isNotNull().contains( fsProvider.getFileStore( path ) ); }
@Test public void testPathEqualsWithDifferentRepos() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final Git git1 = setupGit(); final JGitFileSystem fileSystem1 = new JGitFileSystem( fsProvider, null, git1, "my-repo1", CredentialsProvider.getDefault() ); final Git git2 = setupGit(); final JGitFileSystem fileSystem2 = new JGitFileSystem( fsProvider, null, git2, "my-repo2", CredentialsProvider.getDefault() ); final Path path1 = fileSystem1.getPath( "master", "/path/to/some.txt" ); final Path path2 = fileSystem2.getPath( "master", "/path/to/some.txt" ); assertThat( path1 ).isNotEqualTo( path2 ); assertThat( path1 ).isEqualTo( fileSystem1.getPath( "/path/to/some.txt" ) ); }
assertThat( fs.getRootDirectories() ).hasSize( 2 ); assertThat( fs.getRootDirectories() ).hasSize( 3 ); assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 2 ); } else if ( root.toAbsolutePath().toUri().toString().contains( "origin" ) ) { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 1 ); } else { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 2 ); assertThat( fs.getRootDirectories() ).hasSize( 3 ); assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 3 ); } else if ( root.toAbsolutePath().toUri().toString().contains( "origin" ) ) { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 1 ); } else { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 3 );
@Test public void testFileStore() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final File tempDir = createTempDirectory(); final Git git = setupGit( tempDir ); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); assertThat( fileSystem.getFileStores() ).hasSize( 1 ); final FileStore fileStore = fileSystem.getFileStores().iterator().next(); assertThat( fileStore ).isNotNull(); assertThat( fileStore.getTotalSpace() ).isEqualTo( tempDir.getTotalSpace() ); assertThat( fileStore.getUsableSpace() ).isEqualTo( tempDir.getUsableSpace() ); }
@Test public void simpleTests() { final FileSystem fileSystem = new SimpleWindowsFileSystem( roots, fsProvider, "c:\\" ); assertThat( fileSystem.isOpen() ).isTrue(); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( "\\" ); assertThat( fileSystem.provider() ).isEqualTo( fsProvider ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 1 ).contains( "basic" ); assertThat( fileSystem.getPath( "c:\\path\\to\\file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); assertThat( fileSystem.getPath( "c:\\path\\to\\file.txt", null ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); assertThat( fileSystem.getPath( "c:\\path", "to", "file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); try { fileSystem.close(); fail( "can't close this fileSystem" ); } catch ( UnsupportedOperationException ex ) { } assertThat( fileSystem.getFileStores() ).isNotNull().hasSize( 2 ); assertThat( fileSystem.getFileStores().iterator().next().name() ).isEqualTo( "c:\\" ); assertThat( fileSystem.getRootDirectories() ).isNotNull().hasSize( 2 ); assertThat( fileSystem.getRootDirectories().iterator().next().toString() ).isEqualTo( "c:\\" ); assertThat( fileSystem.getRootDirectories().iterator().next().isAbsolute() ).isTrue(); }
@Test public void testCopyFiles() throws IOException { final URI newRepo = URI.create( "git://copyasset-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@copyasset-test-repo/myfile1.txt" ) ); { final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); } final Path path2 = PROVIDER.getPath( URI.create( "git://user_branch@copyasset-test-repo/other/path/myfile2.txt" ) ); { final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); outStream2.write( "my cool content".getBytes() ); outStream2.close(); } final Path path3 = PROVIDER.getPath( URI.create( "git://user_branch@copyasset-test-repo/myfile3.txt" ) ); { final OutputStream outStream3 = PROVIDER.newOutputStream( path3 ); outStream3.write( "my cool content".getBytes() ); outStream3.close(); } final Path target = PROVIDER.getPath( URI.create( "git://user_branch@copyasset-test-repo/myfile1.txt" ) ); PROVIDER.copy( path, target ); final DirectoryStream<Path> stream = PROVIDER.newDirectoryStream( PROVIDER.getPath( URI.create( "git://user_branch@copyasset-test-repo/" ) ), null ); for ( Path path1 : stream ) { System.out.println("content: " + path1.toUri()); } assertThat( stream ).isNotNull().hasSize( 3 ); }
@Test public void testGetPath() { final URI newRepo = URI.create("default://default-new-get-repo-name"); PROVIDER.newFileSystem(newRepo, EMPTY_ENV); final Path path = PROVIDER.getPath(URI.create("default://master@default-new-get-repo-name/home")); assertThat(path).isNotNull(); assertThat(path.getRoot().toString()).isEqualTo("/"); assertThat(path.toString()).isEqualTo("/home"); assertThat(path.toUri().getScheme()).isEqualTo("default"); final Path pathRelative = PROVIDER.getPath(URI.create("default://master@default-new-get-repo-name/:home")); assertThat(pathRelative).isNotNull(); assertThat(pathRelative.toUri().toString()).isEqualTo("default://master@default-new-get-repo-name/:home"); assertThat(pathRelative.getRoot().toString()).isEqualTo(""); assertThat(pathRelative.toString()).isEqualTo("home"); }
@Test public void whenGettingAudioTracks_thenDelegatesToTrackSelector() { given(trackSelector.getAudioTracks(any(RendererTypeRequester.class))).willReturn(AUDIO_TRACKS); AudioTracks audioTracks = facade.getAudioTracks(); assertThat(audioTracks).isEqualTo(AUDIO_TRACKS); }