List<RepositoryFile> mockList = mock( List.class );
when( unifiedRepository.getChildren( mockSerializable ) ).thenReturn( mockList );
Iterator<RepositoryFile> mockIterator = mock( Iterator.class );
RepositoryFile repositoryFile2 = mock( RepositoryFile.class );
when( mockIterator.hasNext() ).thenReturn( true, false );
when( mockIterator.next() ).thenReturn( repositoryFile2 );
when( mockList.iterator() ).thenReturn( mockIterator );
when( repositoryFile2.isFolder() ).thenReturn( false );
Serializable mockSerializable2 = mock( Serializable.class );
when( repositoryFile2.getId() ).thenReturn( mockSerializable2 );
SimpleRepositoryFileData mockRepoFileData = mock( SimpleRepositoryFileData.class );
when( unifiedRepository.getDataForRead( mockSerializable2, SimpleRepositoryFileData.class ) ).thenReturn(
mockRepoFileData );
InputStream mockInputStream = new InputStream() {
@Override
public int read() throws IOException {
return -1; // EOF
}
};
when( mockRepoFileData.getStream() ).thenReturn( mockInputStream );
String name2 = "name.txt";
when( repositoryFile2.getName() ).thenReturn( name2 );
File parentDir = new File( System.getProperty( "java.io.tmpdir" ) );
File file = new File( parentDir, name );
// already exists
if ( file.isDirectory() ) {