@Before public void setup() throws NoSuchFieldException { when(mediaFileFactory.createMediaFile(MediaType.PHOTO)).thenReturn(new File("test")); createServiceRequestActivity = new CreateServiceRequestActivity(); descriptionField = new EditText(createServiceRequestActivity); setField(createServiceRequestActivity, "mediaFileFactory", mediaFileFactory); setField(createServiceRequestActivity, "requestAdapter", requestAdapter); setField(createServiceRequestActivity, "serviceSpinner", serviceSpinner); setField(createServiceRequestActivity, "descriptionField", descriptionField); }
@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)); }
@Before public void setup() { when(timeFactory.currentTimeMillis()).thenReturn(NOW); recentEnoughCriteria = new IsRecentEnoughCriteria(); setField(recentEnoughCriteria, "timeFactory", timeFactory); }
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); }