public void testDetectLocationBasedCountry() {
   final Country resultCountry =
       new Country(TestCountryDetector.COUNTRY_ISO, Country.COUNTRY_SOURCE_SIM);
   final Country locationBasedCountry =
       new Country(TestCountryDetector.COUNTRY_ISO, Country.COUNTRY_SOURCE_LOCATION);
   TestCountryDetector countryDetector =
       new TestCountryDetector() {
         @Override
         protected Country getSimBasedCountry() {
           return resultCountry;
         }
       };
   CountryListenerImpl listener = new CountryListenerImpl();
   countryDetector.setCountryListener(listener);
   Country country = countryDetector.detectCountry();
   assertTrue(sameCountry(country, resultCountry));
   assertTrue(countryDetector.locationBasedDetectorStarted());
   countryDetector.notifyLocationBasedListener(locationBasedCountry);
   assertTrue(listener.notified());
   assertTrue(sameCountry(listener.getCountry(), locationBasedCountry));
   assertTrue(countryDetector.locationBasedDetectorStopped());
   assertTrue(countryDetector.locationRefreshStarted());
   countryDetector.stop();
   assertTrue(countryDetector.locationRefreshCancelled());
 }
 public void testNoCountryFound() {
   TestCountryDetector countryDetector = new TestCountryDetector();
   CountryListenerImpl listener = new CountryListenerImpl();
   countryDetector.setCountryListener(listener);
   Country country = countryDetector.detectCountry();
   assertTrue(sameCountry(country, null));
   assertTrue(countryDetector.locationBasedDetectorStarted());
   countryDetector.notifyLocationBasedListener(null);
   assertFalse(listener.notified());
   assertTrue(sameCountry(listener.getCountry(), null));
   assertTrue(countryDetector.locationBasedDetectorStopped());
   assertTrue(countryDetector.locationRefreshStarted());
   countryDetector.stop();
   assertTrue(countryDetector.locationRefreshCancelled());
 }
 public void testDetectNetworkBasedCountry() {
   final Country resultCountry =
       new Country(TestCountryDetector.COUNTRY_ISO, Country.COUNTRY_SOURCE_NETWORK);
   TestCountryDetector countryDetector =
       new TestCountryDetector() {
         @Override
         protected Country getNetworkBasedCountry() {
           return resultCountry;
         }
       };
   CountryListenerImpl listener = new CountryListenerImpl();
   countryDetector.setCountryListener(listener);
   Country country = countryDetector.detectCountry();
   assertTrue(sameCountry(country, resultCountry));
   assertFalse(listener.notified());
   assertFalse(countryDetector.locationBasedDetectorStarted());
   assertFalse(countryDetector.locationRefreshStarted());
   countryDetector.stop();
 }
 public void testStoppingDetector() {
   // Test stopping detector when LocationBasedCountryDetector was started
   final Country resultCountry =
       new Country(TestCountryDetector.COUNTRY_ISO, Country.COUNTRY_SOURCE_SIM);
   TestCountryDetector countryDetector =
       new TestCountryDetector() {
         @Override
         protected Country getSimBasedCountry() {
           return resultCountry;
         }
       };
   CountryListenerImpl listener = new CountryListenerImpl();
   countryDetector.setCountryListener(listener);
   Country country = countryDetector.detectCountry();
   assertTrue(sameCountry(country, resultCountry));
   assertTrue(countryDetector.locationBasedDetectorStarted());
   countryDetector.stop();
   // The LocationBasedDetector should be stopped.
   assertTrue(countryDetector.locationBasedDetectorStopped());
   // The location refresh should not running.
   assertTrue(countryDetector.locationRefreshCancelled());
 }