SolutionRepositoryVfsFileObject implements FileObject { public boolean exists() throws FileSystemException { initFile(); return repositoryFile != null; } SolutionRepositoryVfsFileObject( final String fileRef ); IUnifiedRepository getRepository(); IRepositoryContentConverterHandler getConverterHandler(); String getFileRef(); FileName getName(); URL getURL(); boolean exists(); boolean isHidden(); boolean isReadable(); boolean isWriteable(); FileType getType(); FileObject getParent(); @Override String getPublicURIString(); FileSystem getFileSystem(); FileObject[] getChildren(); FileObject getChild( final String arg0 ); FileObject resolveFile( final String arg0, final NameScope arg1 ); @Override boolean setExecutable( boolean executable, boolean ownerOnly ); @Override boolean setReadable( boolean readable, boolean ownerOnly ); @Override boolean setWritable( boolean writable, boolean ownerOnly ); FileObject resolveFile( final String arg0 ); FileObject[] findFiles( final FileSelector arg0 ); void findFiles( final FileSelector arg0, final boolean arg1, final List arg2 ); boolean delete(); int delete( final FileSelector arg0 ); @Override int deleteAll(); void createFolder(); void createFile(); void copyFrom( final FileObject arg0, final FileSelector arg1 ); void moveTo( final FileObject arg0 ); boolean canRenameTo( final FileObject arg0 ); FileContent getContent(); void close(); void refresh(); boolean isAttached(); boolean isContentOpen(); @Override boolean isExecutable(); @Override boolean isFile(); @Override boolean isFolder(); FileOperations getFileOperations(); InputStream getInputStream(); @VisibleForTesting static void setTestAclHelper( IAclNodeHelper helper ); @Override int compareTo( FileObject file ); @Override Iterator<FileObject> iterator();  }
@Test public void testExists( @mockit.Mocked final RepositoryFile mockRepoFile, @mockit.Mocked final IAclNodeHelper mockAclHelper, @mockit.Mocked final IUnifiedRepository mockUnifiedRepository ) throws FileSystemException { String fileRef = "/etc/mondrian/SteelWheels/schema.xml"; Deencapsulation.setField( SolutionRepositoryVfsFileObject.class, "repository", mockUnifiedRepository ); SolutionRepositoryVfsFileObject testObject = new SolutionRepositoryVfsFileObject( fileRef ); Deencapsulation.setField( testObject, "aclHelper", mockAclHelper ); new mockit.NonStrictExpectations() { { mockUnifiedRepository.getFile( anyString ); result = mockRepoFile; mockAclHelper.canAccess( mockRepoFile, EnumSet.of( RepositoryFilePermission.READ ) ); result = true; } }; assertThat( testObject.exists(), is( true ) ); new Verifications() { { mockUnifiedRepository.getFile( anyString ); times = 2; mockAclHelper.canAccess( mockRepoFile, EnumSet.of( RepositoryFilePermission.READ ) ); times = 1; } }; }
@Test @SuppressWarnings( { "checkstyle:onestatementperline", "multiple statements help understand the mock definition" } ) public void testExistsNot( @mockit.Mocked final IAclNodeHelper mockAclHelper, @mockit.Mocked final IUnifiedRepository mockUnifiedRepository ) throws FileSystemException { String fileRef = "/etc/mondrian/SteelWheels/schema.xml"; Deencapsulation.setField( SolutionRepositoryVfsFileObject.class, "repository", mockUnifiedRepository ); SolutionRepositoryVfsFileObject solutionRepositoryVfsFileObject = new SolutionRepositoryVfsFileObject( fileRef ); Deencapsulation.setField( solutionRepositoryVfsFileObject, "aclHelper", mockAclHelper ); new mockit.NonStrictExpectations() { { mockUnifiedRepository.getFile( anyString ); result = null; mockAclHelper.canAccess( null, EnumSet.of( RepositoryFilePermission.READ ) ); result = true; } }; assertThat( solutionRepositoryVfsFileObject.exists(), is( false ) ); new Verifications() { { mockUnifiedRepository.getFile( anyString ); times = 2; mockAclHelper.canAccess( null, EnumSet.of( RepositoryFilePermission.READ ) ); times = 1; } }; }