CTGeofenceFactory { static CTGeofenceAdapter createGeofenceAdapter(@NonNull Context context) { int googlePlayServicesAvailable = GoogleApiAvailability.getInstance(). isGooglePlayServicesAvailable(context); if (Utils.isFusedLocationApiDependencyAvailable()) { if (googlePlayServicesAvailable == ConnectionResult.SUCCESS) { return new GoogleGeofenceAdapter(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 testCreateGeofenceAdapterTC1() { when(Utils.isFusedLocationApiDependencyAvailable()).thenReturn(true); when(googleApiAvailability.isGooglePlayServicesAvailable(application)).thenReturn(ConnectionResult.SUCCESS); CTGeofenceAdapter geofenceAdapter = CTGeofenceFactory.createGeofenceAdapter(application); Assert.assertNotNull(geofenceAdapter); }
@Test(expected = IllegalStateException.class) public void testCreateGeofenceAdapterTC2() { when(Utils.isFusedLocationApiDependencyAvailable()).thenReturn(true); when(googleApiAvailability.isGooglePlayServicesAvailable(application)) .thenReturn(ConnectionResult.SERVICE_MISSING); CTGeofenceFactory.createGeofenceAdapter(application); }
@Test(expected = IllegalStateException.class) public void testCreateGeofenceAdapterTC3() { when(Utils.isFusedLocationApiDependencyAvailable()).thenReturn(true); when(googleApiAvailability.isGooglePlayServicesAvailable(application)) .thenReturn(ConnectionResult.SERVICE_DISABLED); CTGeofenceFactory.createGeofenceAdapter(application); }
@Test(expected = IllegalStateException.class) public void testCreateGeofenceAdapterTC4() { when(Utils.isFusedLocationApiDependencyAvailable()).thenReturn(false); CTGeofenceFactory.createGeofenceAdapter(application); }