@Test public void testActionDelete() { CacheWriter cacheWriter = PowerMock.createMock(CacheWriter.class); CacheListAdapter cacheList = PowerMock.createMock(CacheListAdapter.class); Geocache geocache = PowerMock.createMock(Geocache.class); TitleUpdater titleUpdater = PowerMock.createMock(TitleUpdater.class); DbFrontend dbFrontend = PowerMock.createMock(DbFrontend.class); CachesProviderDb cachesProviderDb = PowerMock.createMock(CachesProviderDb.class); expect(dbFrontend.getCacheWriter()).andReturn(cacheWriter); expect(geocache.getId()).andReturn("GC123"); cacheWriter.deleteCache("GC123"); cacheList.forceRefresh(); titleUpdater.refresh(); cachesProviderDb.notifyOfDbChange(); PowerMock.replayAll(); new CacheActionDelete(cacheList, titleUpdater, dbFrontend, cachesProviderDb, null) .act(geocache); PowerMock.verifyAll(); }
@SuppressWarnings("unchecked") @Test public void testRefresh() { LocationControlBuffered locationControlBuffered = PowerMock.createMock(LocationControlBuffered.class); Location location = PowerMock.createMock(Location.class); Provider<DbFrontend> dbFrontendProvider = PowerMock.createMock(Provider.class); DbFrontend dbFrontend = PowerMock.createMock(DbFrontend.class); WhereFactory whereFactory = PowerMock.createMock(WhereFactory.class); CacheListData cacheListData = PowerMock.createMock(CacheListData.class); TitleUpdater titleUpdater = PowerMock.createMock(TitleUpdater.class); FilterNearestCaches filterNearestCaches = PowerMock.createMock(FilterNearestCaches.class); ActivityVisible activityVisible = PowerMock.createMock(ActivityVisible.class); ArrayList<Geocache> geocaches = new ArrayList<Geocache>(); EasyMock.expect(activityVisible.getVisible()).andReturn(true); EasyMock.expect(location.getLatitude()).andReturn(37.0); EasyMock.expect(location.getLongitude()).andReturn(-122.0); EasyMock.expect(filterNearestCaches.getWhereFactory()).andReturn(whereFactory); EasyMock.expect(locationControlBuffered.getLocation()).andReturn(location); EasyMock.expect(dbFrontendProvider.get()).andReturn(dbFrontend); EasyMock.expect(dbFrontend.loadCaches(37.0, -122.0, whereFactory)).andReturn(geocaches); EasyMock.expect(cacheListData.size()).andReturn(100); EasyMock.expect(dbFrontend.countAll()).andReturn(2300); cacheListData.add(geocaches, locationControlBuffered); titleUpdater.update(2300, 100); PowerMock.replayAll(); new SqlCacheLoader( dbFrontendProvider, filterNearestCaches, cacheListData, locationControlBuffered, titleUpdater, mTiming, activityVisible) .refresh(); PowerMock.verifyAll(); }