ImportFilesRepositoryCustomImpl implements ImportFilesRepositoryCustom { @Override public void saveFileObj(String appIdentifier, File obj) throws IOException{ GridFS gridFS = getGridFS(collectionNameObj); removeFile(appIdentifier,gridFS); saveFile(appIdentifier,obj,gridFS); }  @Override void saveFileMap(String appIdentifier, File map); @Override void saveFileOSM(String appIdentifier, File osm); @Override void saveFileObj(String appIdentifier, File obj);  }
@Test public void saveFileObj() throws Exception{ Mockito.when(mongoTemplate.getDb()).thenReturn(db); PowerMockito.whenNew(GridFS.class).withArguments(db, collectionNameObj).thenReturn(gridFS); Mockito.when(gridFS.findOne(idApp)).thenReturn(gridFSFile); Mockito.when(gridFS.createFile(file)).thenReturn(gridFSInputFile); importFilesRepositoryCustomImpl.saveFileObj(idApp,file); Mockito.verify(gridFS).remove(gridFSFile); Mockito.verify(gridFS).createFile(file); Mockito.verify(gridFSInputFile).setFilename(idApp); Mockito.verify(gridFSInputFile).save(); }
@Test public void saveFileObjWithoutRemoving() throws Exception{ Mockito.when(mongoTemplate.getDb()).thenReturn(db); PowerMockito.whenNew(GridFS.class).withArguments(db, collectionNameObj).thenReturn(gridFS); Mockito.when(gridFS.findOne(idApp)).thenReturn(null); Mockito.when(gridFS.createFile(file)).thenReturn(gridFSInputFile); importFilesRepositoryCustomImpl.saveFileObj(idApp,file); Mockito.verify(gridFS).createFile(file); Mockito.verify(gridFSInputFile).setFilename(idApp); Mockito.verify(gridFSInputFile).save(); }