Weather API test: Wait for a bit before Mockito verifies if method was called
Sometimes the runnable posted to runOnServiceThread() might run a bit faster than the calls made to the mocked weather provider, which causes Mockito to throw an exception. Add a timeout to instruct Mockito to wait for a bit before it verifies if the method was actually called. Also removed an unused variable in CMWeatherManagerTest TICKET: CYNGNOS-3043 Change-Id: I53b6541aeb571a6c83d1c26b6723d74c3661e8cc
This commit is contained in:
parent
3251a4506f
commit
b25a32413c
|
@ -46,7 +46,6 @@ public class CMWeatherManagerTest extends AndroidTestCase {
|
|||
private static final int REQUEST_ID = 42;
|
||||
private static final String MOCKED_WEATHER_PROVIDER_LABEL = "Mock'd Weather Service";
|
||||
private ICMWeatherManager.Stub mICMWeatherManagerSpy;
|
||||
private static final String DESCRIPTOR = "cyanogenmod.weather.ICMWeatherManager";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
|
|
|
@ -45,6 +45,7 @@ public class WeatherProviderServiceTest extends ThreadServiceTestCase<MockWeathe
|
|||
}
|
||||
|
||||
private static final String CITY_NAME = "Seattle";
|
||||
private static final int TIMEOUT = 5000;
|
||||
|
||||
public void testCityNameLookupRequest() throws Exception {
|
||||
IBinder binder = bindService((ServiceRunnable) null);
|
||||
|
@ -61,7 +62,7 @@ public class WeatherProviderServiceTest extends ThreadServiceTestCase<MockWeathe
|
|||
ArgumentCaptor<ServiceRequest> params
|
||||
= ArgumentCaptor.forClass(ServiceRequest.class);
|
||||
|
||||
Mockito.verify(getService().getCallTracker(), Mockito.times(1))
|
||||
Mockito.verify(getService().getCallTracker(), Mockito.timeout(TIMEOUT).times(1))
|
||||
.onRequestSubmitted(params.capture());
|
||||
|
||||
ServiceRequest request = params.getValue();
|
||||
|
@ -88,7 +89,7 @@ public class WeatherProviderServiceTest extends ThreadServiceTestCase<MockWeathe
|
|||
ArgumentCaptor<ServiceRequest> params
|
||||
= ArgumentCaptor.forClass(ServiceRequest.class);
|
||||
|
||||
Mockito.verify(getService().getCallTracker(), Mockito.times(1))
|
||||
Mockito.verify(getService().getCallTracker(), Mockito.timeout(TIMEOUT).times(1))
|
||||
.onRequestSubmitted(params.capture());
|
||||
|
||||
ServiceRequest request = params.getValue();
|
||||
|
@ -117,7 +118,7 @@ public class WeatherProviderServiceTest extends ThreadServiceTestCase<MockWeathe
|
|||
ArgumentCaptor<ServiceRequest> params
|
||||
= ArgumentCaptor.forClass(ServiceRequest.class);
|
||||
|
||||
Mockito.verify(getService().getCallTracker(), Mockito.times(1))
|
||||
Mockito.verify(getService().getCallTracker(), Mockito.timeout(TIMEOUT).times(1))
|
||||
.onRequestSubmitted(params.capture());
|
||||
|
||||
ServiceRequest request = params.getValue();
|
||||
|
@ -211,7 +212,7 @@ public class WeatherProviderServiceTest extends ThreadServiceTestCase<MockWeathe
|
|||
ArgumentCaptor<ServiceRequest> params
|
||||
= ArgumentCaptor.forClass(ServiceRequest.class);
|
||||
|
||||
Mockito.verify(getService().getCallTracker(), Mockito.times(1))
|
||||
Mockito.verify(getService().getCallTracker(), Mockito.timeout(TIMEOUT).times(1))
|
||||
.onRequestSubmitted(params.capture());
|
||||
|
||||
ServiceRequest request = params.getValue();
|
||||
|
@ -227,7 +228,7 @@ public class WeatherProviderServiceTest extends ThreadServiceTestCase<MockWeathe
|
|||
ArgumentCaptor<ServiceRequest> params
|
||||
= ArgumentCaptor.forClass(ServiceRequest.class);
|
||||
|
||||
Mockito.verify(getService().getCallTracker(), Mockito.times(1))
|
||||
Mockito.verify(getService().getCallTracker(), Mockito.timeout(TIMEOUT).times(1))
|
||||
.onRequestSubmitted(params.capture());
|
||||
|
||||
ServiceRequest request = params.getValue();
|
||||
|
@ -243,7 +244,7 @@ public class WeatherProviderServiceTest extends ThreadServiceTestCase<MockWeathe
|
|||
ArgumentCaptor<ServiceRequest> params
|
||||
= ArgumentCaptor.forClass(ServiceRequest.class);
|
||||
|
||||
Mockito.verify(getService().getCallTracker(), Mockito.times(1))
|
||||
Mockito.verify(getService().getCallTracker(), Mockito.timeout(TIMEOUT).times(1))
|
||||
.onRequestSubmitted(params.capture());
|
||||
|
||||
ServiceRequest request = params.getValue();
|
||||
|
|
Loading…
Reference in New Issue