@Test
public void generateAdUrl_whenLocationServiceGpsProviderHasMostRecentLocation_shouldUseLocationServiceValue() {

    Location locationFromDeveloper = new Location("");
    locationFromDeveloper.setLatitude(42);
    locationFromDeveloper.setLongitude(-42);
    locationFromDeveloper.setAccuracy(3.5f);
    locationFromDeveloper.setTime(1000);
    // Mock out the LocationManager's last known location to be more recent than the
    // developer-supplied location.
    ShadowLocationManager shadowLocationManager = Robolectric.shadowOf(
            (LocationManager) application.getSystemService(Context.LOCATION_SERVICE));
    Location locationFromSdk = new Location("");
    locationFromSdk.setLatitude(37);
    locationFromSdk.setLongitude(-122);
    locationFromSdk.setAccuracy(5.0f);
    locationFromSdk.setTime(2000);
    shadowLocationManager.setLastKnownLocation(LocationManager.GPS_PROVIDER, locationFromSdk);
    String adUrl = subject.withLocation(locationFromDeveloper)
            .generateUrlString("ads.mopub.com");
    assertThat(getParameterFromRequestUrl(adUrl, "ll")).isEqualTo("37.0,-122.0");
    assertThat(getParameterFromRequestUrl(adUrl, "lla")).isEqualTo("5");
    assertThat(getParameterFromRequestUrl(adUrl, "llsdk")).isEqualTo("1");
}