コード例 #1
0
  /** Tests {@link LocationMessageHandler#handleMessage}: Only location is transmitted. */
  public void testHandleMessage_Location() {
    // Configure Test
    location = true;
    bearing = true;
    speed = true;
    initFeatures();
    initMyLocation();

    // Looking from myLocation to remoteLocation:
    // 42,45 +-0,1 km distance, -2° +-1 bearing
    logicListenerMock.setDistance(AndroidMock.eq(42.45f * 1000, 100), AndroidMock.eq(-2f, 1f));

    // Run Test
    Location remoteLocation = new Location((String) null);
    setLatLong(remoteLocation);
    runTest(remoteLocation);

    // Verify Test
    verifyFieldMocks();
  }
コード例 #2
0
  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);
  }