本文整理匯總了Java中org.robolectric.Robolectric.flushBackgroundThreadScheduler方法的典型用法代碼示例。如果您正苦於以下問題:Java Robolectric.flushBackgroundThreadScheduler方法的具體用法?Java Robolectric.flushBackgroundThreadScheduler怎麽用?Java Robolectric.flushBackgroundThreadScheduler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.robolectric.Robolectric
的用法示例。
在下文中一共展示了Robolectric.flushBackgroundThreadScheduler方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testNoBidForUnregisteredAd
import org.robolectric.Robolectric; //導入方法依賴的package包/類
@Test
public void testNoBidForUnregisteredAd() throws Exception {
// Cache a bid
ArrayList<BidResponse> bids = new ArrayList<>();
BidResponse testBid = new BidResponse(TestConstants.cpm3, ServerResponses.ut_url);
testBid.addCustomKeyword("pb_cache_id", "14y3834yq5iu5");
testBid.addCustomKeyword("hb_pb", "0.54");
testBid.addCustomKeyword("hb_bidder", "mock_bidder");
bids.add(testBid);
MockServer.addTestSetup(TestConstants.configID1, bids);
ArrayList<AdUnit> adUnits = new ArrayList<AdUnit>();
adUnits.add(adUnit1);
Prebid.init(activity.getApplicationContext(), adUnits, TestConstants.accountId);
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
ArrayList<BidResponse> bidForAdUnit = BidManager.getWinningBids(adUnit1.getCode());
assertNotNull(bidForAdUnit);
BannerAdUnit randomAdUnit = new BannerAdUnit("Random", TestConstants.configID1);
bidForAdUnit = BidManager.getWinningBids(randomAdUnit.getCode());
assertNull(bidForAdUnit);
}
示例2: setup
import org.robolectric.Robolectric; //導入方法依賴的package包/類
@Before
public void setup() {
activity = Robolectric.buildActivity(MockMainActivity.class).create().get();
// activity = Robolectric.setupActivity(MockMainActivity.class);
shadowOf(activity).grantPermissions("android.permission.INTERNET");
server = new MockWebServer();
try {
server.start();
successfulMockServerStarted = true;
} catch (IOException e) {
e.printStackTrace();
}
FakeHttp.getFakeHttpLayer().interceptHttpRequests(true);
FakeHttp.getFakeHttpLayer().interceptResponseContent(true);
bgScheduler = Robolectric.getBackgroundThreadScheduler();
uiScheduler = Robolectric.getForegroundThreadScheduler();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
bgScheduler.pause();
uiScheduler.pause();
}
示例3: testCachingOfBidsInit
import org.robolectric.Robolectric; //導入方法依賴的package包/類
@Test
public void testCachingOfBidsInit() throws Exception {
// Check that at the beginning response for identifier is empty
ArrayList<BidResponse> nullBidResponseForAdSlot1 = BidManager.getWinningBids(adUnit1.getCode());
assertNull(nullBidResponseForAdSlot1);
ArrayList<BidResponse> nullBidResponseForAdSlot2 = BidManager.getWinningBids(adUnit2.getCode());
assertNull(nullBidResponseForAdSlot2);
// Start running auctions,should get immediate response
ArrayList<AdUnit> adUnits = new ArrayList<AdUnit>();
adUnits.add(adUnit1);
adUnits.add(adUnit2);
// Set up test responses
ArrayList<BidResponse> bids = new ArrayList<>();
BidResponse testBid = new BidResponse(TestConstants.cpm1, ServerResponses.ut_url);
bids.add(testBid);
ArrayList<BidResponse> bids2 = new ArrayList<>();
BidResponse testBid2 = new BidResponse(TestConstants.cpm2, ServerResponses.ut_url);
bids2.add(testBid2);
MockServer.addTestSetup(TestConstants.configID1, bids);
MockServer.addTestSetup(TestConstants.configID2, bids2);
// Init prebid with ad units
Prebid.init(activity.getApplicationContext(), adUnits, TestConstants.accountId);
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
// Check a response is cached
ArrayList<BidResponse> bidForAdSlot1 = BidManager.getWinningBids(adUnit1.getCode());
assertNotNull(bidForAdSlot1);
assertEquals(TestConstants.cpm1, bidForAdSlot1.get(0).getCpm());
ArrayList<BidResponse> bidForAdSlot2 = BidManager.getWinningBids(adUnit2.getCode());
assertNotNull(bidForAdSlot2);
assertEquals(TestConstants.cpm2, bidForAdSlot2.get(0).getCpm());
}
示例4: testStartNewAuction
import org.robolectric.Robolectric; //導入方法依賴的package包/類
@Test
public void testStartNewAuction() throws Exception {
// Cache a bid
ArrayList<AdUnit> adUnits = new ArrayList<AdUnit>();
adUnits.add(adUnit1);
Prebid.init(activity.getApplicationContext(), adUnits, TestConstants.accountId);
// Here is where we call start new Auction.
ArrayList<BidResponse> bids = new ArrayList<>();
bids.add(new BidResponse(TestConstants.cpm3, ServerResponses.ut_url));
MockServer.addTestSetup(TestConstants.configID1, bids);
BidManager.startNewAuction(activity.getApplicationContext(), adUnit1);
// Run tasks
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
ArrayList<BidResponse> bidForAdSlot_1 = BidManager.getWinningBids(adUnit1.getCode());
assertNotNull(bidForAdSlot_1);
assertEquals(TestConstants.cpm3, bidForAdSlot_1.get(0).getCpm());
MockServer.clearSetUps();
ArrayList<BidResponse> bids2 = new ArrayList<>();
bids2.add(new BidResponse(TestConstants.cpm2, ServerResponses.ut_url));
MockServer.addTestSetup(TestConstants.configID1, bids2);
BidManager.startNewAuction(activity.getApplicationContext(), adUnit1);
// Run tasks
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
bidForAdSlot_1 = BidManager.getWinningBids(adUnit1.getCode());
assertNotNull(bidForAdSlot_1);
assertEquals(TestConstants.cpm2, bidForAdSlot_1.get(0).getCpm());
}
示例5: testKeywordString
import org.robolectric.Robolectric; //導入方法依賴的package包/類
@Test
public void testKeywordString() throws Exception {
//Registering a list of adUnits test
ArrayList<BidResponse> bids = new ArrayList<>();
BidResponse testBid = new BidResponse(TestConstants.cpm3, ServerResponses.ut_url);
testBid.addCustomKeyword("pb_cache_id", "14y3834yq5iu5");
testBid.addCustomKeyword("hb_pb", "0.54");
testBid.addCustomKeyword("hb_bidder", "mock_bidder");
bids.add(testBid);
MockServer.addTestSetup(TestConstants.configID1, bids);
ArrayList<AdUnit> adUnits = new ArrayList<AdUnit>();
adUnits.add(adUnit1);
Prebid.init(activity.getApplicationContext(), adUnits, TestConstants.accountId);
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
ArrayList<Pair<String, String>> keywords = BidManager.getKeywordsForAdUnit(adUnit1.getCode(), activity.getApplicationContext());
for (Pair keywordPair : keywords) {
if ("pb_cache_id".equals(keywordPair.first)) {
assertEquals("14y3834yq5iu5", keywordPair.second);
} else if ("hb_pb".equals(keywordPair.first)) {
assertEquals("0.54", keywordPair.second);
} else if ("hb_bidder".equals(keywordPair.first)) {
assertEquals("mock_bidder", keywordPair.second);
}
}
}