FileDocCategorySizeDatePackage
CountryDetectorServiceTest.javaAPI DocAndroid 5.1 API3864Thu Mar 12 22:22:42 GMT 2015com.android.server

CountryDetectorServiceTest

public class CountryDetectorServiceTest extends android.test.AndroidTestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtestAddRemoveListener()

        CountryDetectorServiceTester serviceTester = new CountryDetectorServiceTester(getContext());
        serviceTester.systemRunning();
        waitForSystemReady(serviceTester);
        CountryListenerTester listenerTester = new CountryListenerTester();
        serviceTester.addCountryListener(listenerTester);
        assertTrue(serviceTester.isListenerSet());
        serviceTester.removeCountryListener(listenerTester);
        assertFalse(serviceTester.isListenerSet());
    
public voidtestNotifyListeners()

        CountryDetectorServiceTester serviceTester = new CountryDetectorServiceTester(getContext());
        CountryListenerTester listenerTesterA = new CountryListenerTester();
        CountryListenerTester listenerTesterB = new CountryListenerTester();
        Country country = new Country("US", Country.COUNTRY_SOURCE_NETWORK);
        serviceTester.systemRunning();
        waitForSystemReady(serviceTester);
        serviceTester.addCountryListener(listenerTesterA);
        serviceTester.addCountryListener(listenerTesterB);
        serviceTester.notifyReceivers(country);
        assertTrue(serviceTester.isListenerSet());
        assertTrue(listenerTesterA.isNotified());
        assertTrue(listenerTesterB.isNotified());
        serviceTester.removeCountryListener(listenerTesterA);
        serviceTester.removeCountryListener(listenerTesterB);
        assertFalse(serviceTester.isListenerSet());
    
private voidwaitForSystemReady(CountryDetectorService service)

        int count = 5;
        while (count-- > 0) {
            try {
                Thread.sleep(500);
            } catch (Exception e) {
            }
            if (service.isSystemReady()) {
                return;
            }
        }
        throw new RuntimeException("Wait System Ready timeout");