@Before public void setup() { bestLocationDelegate = new BestLocationDelegate(null, null, null, null); List<String> providers = new ArrayList<String>(); when(locationManager.getAllProviders()).thenReturn(providers); TestHelper.setField(bestLocationDelegate, "locationManager", locationManager); when(passesCriteria.passes(any(Location.class), any(Location.class))).thenReturn(true); when(failsCriteria.passes(any(Location.class), any(Location.class))).thenReturn(false); List<LocationCriteria> criteria = new ArrayList<LocationCriteria>(); TestHelper.setField(bestLocationDelegate, "criteria", criteria); }
@Test public void shouldFailIfLocationIsNull() { IsRecentEnoughCriteria recentEnoughCriteriaNullLocation = new IsRecentEnoughCriteria(); TestHelper.setField(recentEnoughCriteriaNullLocation, "timeFactory", timeFactory); assertThat(recentEnoughCriteriaNullLocation.passes(null, null), is(false)); }
private void mockAccurateLocation(LocationManager locationManager) { locationManager.getAllProviders().add(LocationManager.GPS_PROVIDER); when(locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)) .thenReturn(candidateLocation); TestHelper.setField(bestLocationDelegate, "locationManager", locationManager); }
private void mockLessAccurateLocation(LocationManager locationManager) { locationManager.getAllProviders().add(LocationManager.NETWORK_PROVIDER); when(locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)) .thenReturn(previousLocation); TestHelper.setField(bestLocationDelegate, "locationManager", locationManager); }
private void addCriteria(LocationCriteria locationCriteria) { List<LocationCriteria> criteria = (List<LocationCriteria>) TestHelper.getField(bestLocationDelegate, "criteria"); criteria.add(locationCriteria); }