use of org.robolectric.shadows.ShadowLooper in project glide by bumptech.
the class EngineJobTest method testReleasesResourceIfCancelledOnReady.
@Test
public void testReleasesResourceIfCancelledOnReady() {
ShadowLooper shadowLooper = Shadows.shadowOf(harness.mainHandler.getLooper());
shadowLooper.pause();
EngineJob<Object> job = harness.getJob();
job.start(harness.decodeJob);
job.onResourceReady(harness.resource, harness.dataSource);
job.cancel();
shadowLooper.runOneTask();
verify(harness.resource).recycle();
}
use of org.robolectric.shadows.ShadowLooper in project prebid-mobile-android by prebid.
the class AdUnitContentTest method testAdUnitUsingContentUrl.
@Test
public void testAdUnitUsingContentUrl() throws Exception {
final String expectedContentUrl = "http://www.something.com/somewhere/here";
HttpUrl hostUrl = server.url("/");
Host.CUSTOM.setHostUrl(hostUrl.toString());
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
PrebidMobile.setApplicationContext(activity.getApplicationContext());
PrebidMobile.setPrebidServerAccountId("123456");
final CompletableFuture<JSONObject> future = new CompletableFuture<>();
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
String postData = request.getBody().readUtf8();
try {
JSONObject jsonObject = new JSONObject(postData);
future.complete(jsonObject);
} catch (JSONException err) {
Log.d("Error", err.toString());
future.cancel(true);
}
return new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.noBid());
}
});
BannerAdUnit adUnit = new BannerAdUnit("123456", 320, 50);
ContentObject contentObject = new ContentObject();
contentObject.setUrl(expectedContentUrl);
adUnit.setAppContent(contentObject);
adUnit.fetchDemand(new OnCompleteListener2() {
@Override
public void onComplete(ResultCode resultCode, Map<String, String> unmodifiableMap) {
System.out.println("I am in onComplete " + resultCode.toString());
future.cancel(true);
}
});
DemandFetcher fetcher = (DemandFetcher) FieldUtils.readField(adUnit, "fetcher", true);
ShadowLooper fetcherLooper = shadowOf(fetcher.getHandler().getLooper());
fetcherLooper.runOneTask();
ShadowLooper demandLooper = shadowOf(fetcher.getDemandHandler().getLooper());
demandLooper.runOneTask();
ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runToEndOfTasks();
JSONObject requestBody = future.get(10, TimeUnit.SECONDS);
JSONObject app = requestBody.getJSONObject("app");
assertTrue(app.has("content"));
JSONObject content = app.getJSONObject("content");
assertTrue(content.has("url"));
assertEquals(expectedContentUrl, content.getString("url"));
}
use of org.robolectric.shadows.ShadowLooper in project prebid-mobile-android by prebid.
the class PrebidServerAdapterTest method testInvalidPrebidServerConfigIdForAppNexusHostedPrebidServer.
// @Test
// TODO: Activate this test after setting up test server
public void testInvalidPrebidServerConfigIdForAppNexusHostedPrebidServer() {
PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
PrebidMobile.setShareGeoLocation(true);
PrebidMobile.setApplicationContext(activity.getApplicationContext());
DemandAdapter.DemandAdapterListener mockListener = mock(DemandAdapter.DemandAdapterListener.class);
PrebidServerAdapter adapter = new PrebidServerAdapter();
HashSet<AdSize> sizes = new HashSet<>();
sizes.add(new AdSize(320, 50));
RequestParams requestParams = new RequestParams("6ace8c7d-88c0-4623-8117-ffffffffffff", AdType.BANNER, sizes);
String uuid = UUID.randomUUID().toString();
adapter.requestDemand(requestParams, mockListener, uuid);
ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runToEndOfTasks();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
verify(mockListener).onDemandFailed(ResultCode.INVALID_CONFIG_ID, uuid);
}
use of org.robolectric.shadows.ShadowLooper in project prebid-mobile-android by prebid.
the class PrebidServerAdapterTest method testRubiconDefaultError.
@Test
public void testRubiconDefaultError() {
server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.htmlUnreachableFromRubicon()));
HttpUrl hostUrl = server.url("/");
Host.CUSTOM.setHostUrl(hostUrl.toString());
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
PrebidMobile.setPrebidServerAccountId("12345");
PrebidMobile.setApplicationContext(activity.getApplicationContext());
DemandAdapter.DemandAdapterListener mockListener = mock(DemandAdapter.DemandAdapterListener.class);
PrebidServerAdapter adapter = new PrebidServerAdapter();
HashSet<AdSize> sizes = new HashSet<>();
sizes.add(new AdSize(320, 50));
RequestParams requestParams = new RequestParams("67890", AdType.BANNER, sizes);
String uuid = UUID.randomUUID().toString();
adapter.requestDemand(requestParams, mockListener, uuid);
ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runToEndOfTasks();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
verify(mockListener).onDemandFailed(ResultCode.PREBID_SERVER_ERROR, uuid);
}
use of org.robolectric.shadows.ShadowLooper in project prebid-mobile-android by prebid.
the class PrebidServerAdapterTest method testSuccessfulBidResponseWithoutCacheId.
@Test
public void testSuccessfulBidResponseWithoutCacheId() {
server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.invalidBidResponseWithoutCacheId()));
HttpUrl hostUrl = server.url("/");
Host.CUSTOM.setHostUrl(hostUrl.toString());
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
PrebidMobile.setPrebidServerAccountId("12345");
PrebidMobile.setShareGeoLocation(true);
PrebidMobile.setApplicationContext(activity.getApplicationContext());
DemandAdapter.DemandAdapterListener mockListener = mock(DemandAdapter.DemandAdapterListener.class);
PrebidServerAdapter adapter = new PrebidServerAdapter();
HashSet<AdSize> sizes = new HashSet<>();
sizes.add(new AdSize(300, 250));
RequestParams requestParams = new RequestParams("67890", AdType.BANNER, sizes);
String uuid = UUID.randomUUID().toString();
adapter.requestDemand(requestParams, mockListener, uuid);
ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runToEndOfTasks();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
verify(mockListener).onDemandFailed(ResultCode.NO_BIDS, uuid);
}
Aggregations