public void testLastKnownLocationNotAvailable() {

    final String strProvider = "foobar";

    AndroidMock.expect(appUtils.hasPermission(context, "android.permission.ACCESS_FINE_LOCATION"))
        .andReturn(true)
        .anyTimes();
    AndroidMock.expect(
            locationManager.getBestProvider(
                (Criteria) AndroidMock.anyObject(), AndroidMock.eq(true)))
        .andReturn(strProvider)
        .anyTimes();
    AndroidMock.expect(locationManager.getLastKnownLocation(strProvider))
        .andReturn(null)
        .anyTimes();
    AndroidMock.expect(locationManager.isProviderEnabled(strProvider)).andReturn(true).anyTimes();
    AndroidMock.expect(locationListenerFactory.getBean()).andReturn(listener).anyTimes();

    locationManager.requestLocationUpdates(context, strProvider, 1L, 0.0f, listener);

    AndroidMock.replay(locationListenerFactory);
    AndroidMock.replay(appUtils);
    AndroidMock.replay(locationManager);

    DefaultLocationProvider provider = new DefaultLocationProvider();
    provider.setLocationManager(locationManager);
    provider.setAppUtils(appUtils);
    provider.setLocationListenerFactory(locationListenerFactory);
    provider.init(context);

    Location loc = provider.getLastKnownLocation();

    AndroidMock.verify(locationListenerFactory);
    AndroidMock.verify(appUtils);
    AndroidMock.verify(locationManager);

    assertNull(loc);
  }
  public void testLastKnownLocationAvailable() {

    final String strProvider = "foobar";

    Location location = AndroidMock.createMock(Location.class, strProvider);

    AndroidMock.expect(appUtils.hasPermission(context, "android.permission.ACCESS_FINE_LOCATION"))
        .andReturn(true);
    AndroidMock.expect(
            locationManager.getBestProvider(
                (Criteria) AndroidMock.anyObject(), AndroidMock.eq(true)))
        .andReturn(strProvider);
    AndroidMock.expect(locationManager.getLastKnownLocation(strProvider)).andReturn(location);
    AndroidMock.expect(config.getBooleanProperty(SocializeConfig.SOCIALIZE_LOCATION_ENABLED, true))
        .andReturn(true)
        .anyTimes();

    locationManager.removeUpdates(listener);

    AndroidMock.expect(locationListenerFactory.getBean()).andReturn(listener);

    AndroidMock.replay(appUtils, locationManager, locationListenerFactory, config);

    DefaultLocationProvider provider = new DefaultLocationProvider();
    provider.setLocationManager(locationManager);
    provider.setAppUtils(appUtils);
    provider.setConfig(config);
    provider.setLocationListenerFactory(locationListenerFactory);
    provider.init(context);

    Location loc = provider.getLocation(getContext());

    AndroidMock.verify(appUtils, locationManager, locationListenerFactory, config);

    assertNotNull(loc);
    assertSame(location, loc);
  }