CTLocationFactory { static CTLocationAdapter createLocationAdapter(@NonNull Context context) { int googlePlayServicesAvailable = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context); if (Utils.isFusedLocationApiDependencyAvailable()) { CTGeofenceAPI.getLogger().info(CTGeofenceAPI.GEOFENCE_LOG_TAG, "FusedLocationApi dependency is available"); if (googlePlayServicesAvailable == ConnectionResult.SUCCESS) { CTGeofenceAPI.getLogger().info(CTGeofenceAPI.GEOFENCE_LOG_TAG, "Play service APK is available"); return new GoogleLocationAdapter(context.getApplicationContext()); } else { String errorString = GoogleApiAvailability.getInstance().getErrorString(googlePlayServicesAvailable); throw new IllegalStateException("Play service APK error :: " + errorString); } } else { throw new IllegalStateException("play-services-location dependency is missing"); } }    }
@Test public void testCreateLocationAdapterTC1() { when(Utils.isFusedLocationApiDependencyAvailable()).thenReturn(true); when(googleApiAvailability.isGooglePlayServicesAvailable(application)).thenReturn(ConnectionResult.SUCCESS); CTLocationAdapter LocationAdapter = CTLocationFactory.createLocationAdapter(application); Assert.assertNotNull(LocationAdapter); }
@Test(expected = IllegalStateException.class) public void testCreateLocationAdapterTC2() { when(Utils.isFusedLocationApiDependencyAvailable()).thenReturn(true); when(googleApiAvailability.isGooglePlayServicesAvailable(application)) .thenReturn(ConnectionResult.SERVICE_MISSING); CTLocationFactory.createLocationAdapter(application); }
@Test(expected = IllegalStateException.class) public void testCreateLocationAdapterTC3() { when(Utils.isFusedLocationApiDependencyAvailable()).thenReturn(true); when(googleApiAvailability.isGooglePlayServicesAvailable(application)) .thenReturn(ConnectionResult.SERVICE_DISABLED); CTLocationFactory.createLocationAdapter(application); }
@Test(expected = IllegalStateException.class) public void testCreateLocationAdapterTC4() { when(Utils.isFusedLocationApiDependencyAvailable()).thenReturn(false); CTLocationFactory.createLocationAdapter(application); }