ImportRepositoryCustomImpl implements ImportRepositoryCustom { public void lockImportProcess(String appIdentifier){ if(!mongoTemplate.collectionExists(collectionLock)){ mongoTemplate.createCollection(collectionLock); } LockImport lockImport = new LockImport(); lockImport.setAppIdentifier(appIdentifier); lockImport.setTimeStamp(DateTime.now().toString()); mongoTemplate.save(lockImport, collectionLock); }  @Override String saveGeoJson(String appIdentifier, Collection<Feature> featureCollection); void lockImportProcess(String appIdentifier); boolean isImportProcessLocked(String appIdentifier); void deleteLockImportProcess(String appIdentifier);  }
@Test public void lockImportProcess() throws Exception{ String idApplication = "1"; String strNow = DateTime.now().toString(); Mockito.when(mongoTemplate.collectionExists(collectionLock)).thenReturn(true); Mockito.when(mongoTemplate.getCollection(collectionLock)).thenReturn(dbCollection); PowerMockito.whenNew(LockImport.class).withNoArguments().thenReturn(lockImport); PowerMockito.mockStatic(DateTime.class); Mockito.when(DateTime.now()).thenReturn(now); Mockito.when(now.toString()).thenReturn(strNow); importRepositoryCustom.lockImportProcess(idApplication); verify(lockImport).setAppIdentifier(idApplication); verify(lockImport).setTimeStamp(strNow); verify(mongoTemplate).save(lockImport,collectionLock); }