public void testOutputUriSetAsExtra() { Intent intent = builder.getIntent(activity); Uri output = intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT); assertThat(output.toString()).isEqualTo("image:output"); }
@Test public void zeroInjectionsInjectDoesNotThrowException() { class Example {} Example example = new Example(); bind(example, null); bindNavigationModel(example, null, null); assertThat(EXTRA_BINDERS).contains(entry(Example.class, NO_OP)); assertThat(NAVIGATION_MODEL_BINDERS).contains(entry(Example.class, NO_OP)); }
@Test public void testGetFileStore() throws Exception { final URI newRepo = URI.create( "git://filestore-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@filestore-test-repo/path/to/myfile1.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); final FileStore fileStore = PROVIDER.getFileStore( path ); assertThat( fileStore ).isNotNull(); assertThat( fileStore.getAttribute( "readOnly" ) ).isEqualTo( Boolean.FALSE ); }
@Test public void testSimpleBranchedGitRoot2() { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, "/path/to/some/place.txt", "master@my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/some/place.txt"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/place.txt"); assertThat(path.getNameCount()).isEqualTo(4); assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path"); assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/"); }
@Test public void testNewOutputStreamWithJGitOp() throws Exception { final File parentFolder = createTempDirectory(); final File gitFolder = new File( parentFolder, "mytest.git" ); final Git origin = JGitUtil.newRepository( gitFolder, true ); commit( origin, "master", "user", "user@example.com", "commit message", null, null, false, new HashMap<String, File>() {{ put( "myfile.txt", tempFile( "temp\n.origin\n.content" ) ); }} ); commit( origin, "user_branch", "user", "user@example.com", "commit message", null, null, false, new HashMap<String, File>() {{ put( "path/to/some/file/myfile.txt", tempFile( "some\n.content\nhere" ) ); }} ); final URI newRepo = URI.create( "git://outstreamwithop-test-repo" ); final Map<String, Object> env = new HashMap<String, Object>() {{ put( JGitFileSystemProvider.GIT_DEFAULT_REMOTE_NAME, origin.getRepository().getDirectory().toString() ); }}; final FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); assertThat( fs ).isNotNull(); final SimpleDateFormat formatter = new SimpleDateFormat( "dd/MM/yyyy" ); final CommentedOption op = new CommentedOption( "User Tester", "user.tester@example.com", "omg, is it the end?", formatter.parse( "31/12/2012" ) ); final Path path = PROVIDER.getPath( URI.create( "git://user_branch@outstreamwithop-test-repo/some/path/myfile.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path, op ); assertThat( outStream ).isNotNull(); outStream.write( "my cool content".getBytes() ); outStream.close(); final InputStream inStream = PROVIDER.newInputStream( path ); final String content = new Scanner( inStream ).useDelimiter( "\\A" ).next(); inStream.close(); assertThat( content ).isNotNull().isEqualTo( "my cool content" ); }
@Test public void testMoveFiles() throws IOException { final URI newRepo = URI.create( "git://moveasset-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@moveasset-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@moveasset-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@moveasset-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@moveasset-test-repo/myfile1.txt" ) ); try { PROVIDER.move( path, target ); } catch ( final Exception e ) { fail( "should move file", e ); } }
@Test public void checkNewByteChannelToCreateFile() throws IOException { final SimpleFileSystemProvider fsProvider = new SimpleFileSystemProvider(); final String userBasedPath = System.getProperty( "user.dir" ) + "/byte_some_file_here.txt"; final Path path = GeneralPathImpl.create( fsProvider.getFileSystem( URI.create( "file:///" ) ), userBasedPath, false ); assertThat( path.toFile().exists() ).isFalse(); final SeekableByteChannel channel = fsProvider.newByteChannel( path, null ); assertThat( channel ).isNotNull(); assertThat( path.toFile().exists() ).isTrue(); path.toFile().delete(); assertThat( path.toFile().exists() ).isFalse(); }
@Test public void checkGetFileStore() { final Path path = GeneralPathImpl.create( fsProvider.getFileSystem( URI.create( "file:///" ) ), "c:\\path\\to\\file.txt", false ); assertThat( fsProvider.getFileStore( path ) ).isNotNull().isInstanceOf( SimpleWindowsFileStore.class ); assertThat( fsProvider.getFileStore( path ).name() ).isNotNull().isEqualTo( "c:\\" ); }
@Test public void testInvalidURINewFileSystem() { final URI newRepo = URI.create( "git:///repo-name" ); try { PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); failBecauseExceptionWasNotThrown( IllegalArgumentException.class ); } catch ( final IllegalArgumentException ex ) { assertThat( ex.getMessage() ).isEqualTo( "Parameter named 'uri' is invalid, missing host repository!" ); } }
@Test public void readAttributesInvalid() throws IOException { final SimpleFileSystemProvider fsProvider = new SimpleFileSystemProvider(); final File tempFile = File.createTempFile( "foo", "bar" ); final Path path = GeneralPathImpl.newFromFile( fsProvider.getFileSystem( URI.create( "file:///" ) ), tempFile ); assertThat( fsProvider.readAttributes( path, MyAttrs.class ) ).isNull(); }
@Test public void testOnlyLocalRoot() 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.getRootDirectories() ).hasSize( 1 ); final Path root = fileSystem.getRootDirectories().iterator().next(); assertThat( root.toString() ).isEqualTo( "/" ); assertThat( root.getRoot().toString() ).isEqualTo( "/" ); }
@Test public void simpleStateTest() { assertThat( fsProvider ).isNotNull(); assertThat( fsProvider.getScheme() ).isNotEmpty().isEqualTo( "file" ); final Path path = GeneralPathImpl.create( fsProvider.getFileSystem( URI.create( "file:///" ) ), "c:\\path\\to\\file.txt", false ); assertThat( path.getFileSystem() ).isNotNull().isInstanceOf( SimpleWindowsFileSystem.class ); }
@Test public void validateGetPath() { final SimpleFileSystemProvider fsProvider = new SimpleFileSystemProvider(); final URI uri = URI.create( "file:///path/to/file.txt" ); final Path path = fsProvider.getPath( uri ); assertThat( path ).isNotNull(); assertThat( path.isAbsolute() ).isTrue(); assertThat( path.getFileSystem() ).isEqualTo( fsProvider.getFileSystem( uri ) ); assertThat( path.getFileSystem().provider() ).isEqualTo( fsProvider ); assertThat( path.toString() ).isEqualTo( "/path/to/file.txt" ); }
@Test public void testGetFileSystem() { final URI newRepo = URI.create( "git://new-repo-name" ); final FileSystem fs = PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); assertThat( fs ).isNotNull(); assertThat( PROVIDER.getFileSystem( newRepo ) ).isEqualTo( fs ); assertThat( PROVIDER.getFileSystem( URI.create( "git://master@new-repo-name" ) ) ).isEqualTo( fs ); assertThat( PROVIDER.getFileSystem( URI.create( "git://branch@new-repo-name" ) ) ).isEqualTo( fs ); assertThat( PROVIDER.getFileSystem( URI.create( "git://branch@new-repo-name?fetch" ) ) ).isEqualTo( fs ); }
@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 testProvider() 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.getName() ).isEqualTo( "my-repo" ); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( "/" ); assertThat( fileSystem.provider() ).isEqualTo( fsProvider ); }
@Test public void givenCapableProvisionCapabilities_whenProvisioning_thenTheRequestUrlIsExpected() throws IOException, UnableToProvisionException { ProvisioningCapabilities capabilities = aProvisioningCapabilities().thatCanProvision(); httpPostingProvisionExecutor = new HttpPostingProvisionExecutor(httpPoster, capabilities); String expectedProvisionUrl = PROVISION_URL + "&signedRequest=" + new String(PROVISION_DATA); httpPostingProvisionExecutor.execute(A_PROVISION_REQUEST); verify(httpPoster).post(provisionUrlCaptor.capture()); assertThat(provisionUrlCaptor.getValue()).isEqualTo(expectedProvisionUrl); } }
@Test public void whenGettingPlayerInformation_thenReturnsPlayerInformation() { PlayerInformation playerInformation = player.getPlayerInformation(); assertThat(playerInformation.getPlayerType()).isEqualTo(PlayerType.EXO_PLAYER); assertThat(playerInformation.getVersion()).isEqualTo(ExoPlayerLibraryInfo.VERSION); }
public void testBuildsIntentWithMultipleOptions() { builder.asSquare().withMaxSize(200, 200); Intent intent = builder.getIntent(activity); assertThat(intent.getIntExtra("aspect_x", 0)).isEqualTo(1); assertThat(intent.getIntExtra("aspect_y", 0)).isEqualTo(1); assertThat(intent.getIntExtra("max_x", 0)).isEqualTo(200); assertThat(intent.getIntExtra("max_y", 0)).isEqualTo(200); }
@Test public void joinWithFormatter() { Formatter<Integer> formatter = new Formatter<Integer>() { @Override public CharSequence format(Integer item) { return String.format("0x%d", item); } }; assertThat(listPhrase.join(asList(1, 2, 3), formatter)).isEqualTo("0x1, 0x2, and 0x3"); }