### Question:
LocationUtils { public static Location getLastKnownLocation(final Context context) { if (context == null) { throw new IllegalArgumentException("Context must not be null"); } return getLastKnownLocation((LocationManager) context.getSystemService(Context.LOCATION_SERVICE)); } private  LocationUtils(); static Location getLastKnownLocation(final Context context); static Location getLastKnownLocation(final Context context, final String...providers); static Location getLastKnownLocation(final LocationManager locationManager); static Location getLastKnownLocation(final LocationManager locationManager, final String...providers); static boolean isBetterLocation(final Location currentLocation, final Location newLocation); static boolean isSameProvider(final String provider1, final String provider2);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testGetLastKnownLocationContextIllegalArgumentException() { final Context context = null; LocationUtils.getLastKnownLocation(context); }
@Test public void testGetLastKnownLocationContext() { final Location result = LocationUtils.getLastKnownLocation(Robolectric.application); assertNotNull(result); assertSame(result, mLastKnownLocation); }
@Test(expected = IllegalArgumentException.class) public void testGetLastKnownLocationContextStringArrayIllegalArgumentException() { final Context context = null; LocationUtils.getLastKnownLocation(context, LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER); }
@Test public void testGetLastKnownLocationContextStringArray() { final Location result1 = LocationUtils.getLastKnownLocation(Robolectric.application, LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER); assertNotNull(result1); assertSame(result1, mLastKnownLocation); final Location result2 = LocationUtils.getLastKnownLocation(Robolectric.application, LocationManager.NETWORK_PROVIDER, LocationManager.GPS_PROVIDER); assertNotNull(result2); assertSame(result2, mLastKnownLocation); final Location result3 = LocationUtils.getLastKnownLocation(Robolectric.application, LocationManager.GPS_PROVIDER); assertNotNull(result3); assertSame(result3, mLastKnownLocation); final Location result4 = LocationUtils.getLastKnownLocation(Robolectric.application, LocationManager.NETWORK_PROVIDER); assertNull(result4); }
@Test public void testGetLastKnownLocationLocationManagerStringArray() { final LocationManager locationManager = (LocationManager) Robolectric.application.getSystemService(Context.LOCATION_SERVICE); final LocationManager nullLocationManager = null; final String[] nullProviders = null; assertNull(LocationUtils.getLastKnownLocation(nullLocationManager, nullProviders)); assertNull(LocationUtils.getLastKnownLocation(nullLocationManager, LocationManager.GPS_PROVIDER)); assertNull(LocationUtils.getLastKnownLocation(nullLocationManager, LocationManager.NETWORK_PROVIDER)); assertNull(LocationUtils.getLastKnownLocation(nullLocationManager, LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER)); assertNull(LocationUtils.getLastKnownLocation(locationManager, nullProviders)); assertNotNull(LocationUtils.getLastKnownLocation(locationManager, LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER)); }