Search in sources :

Example 16 with LooperMode

use of org.robolectric.annotation.LooperMode in project robolectric by robolectric.

the class ShadowContextWrapperTest method sendBroadcast_shouldSendIntentUsingHandlerIfOneIsProvided_legacy.

@Test
@LooperMode(LEGACY)
public void sendBroadcast_shouldSendIntentUsingHandlerIfOneIsProvided_legacy() {
    HandlerThread handlerThread = new HandlerThread("test");
    handlerThread.start();
    Handler handler = new Handler(handlerThread.getLooper());
    assertNotSame(handler.getLooper(), Looper.getMainLooper());
    BroadcastReceiver receiver = broadcastReceiver("Larry");
    contextWrapper.registerReceiver(receiver, intentFilter("foo", "baz"), null, handler);
    assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(0);
    contextWrapper.sendBroadcast(new Intent("foo"));
    assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(1);
    shadowOf(handlerThread.getLooper()).idle();
    assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(0);
    asyncAssertThat(transcript).containsExactly("Larry notified of foo");
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) Test(org.junit.Test) LooperMode(org.robolectric.annotation.LooperMode)

Example 17 with LooperMode

use of org.robolectric.annotation.LooperMode in project materialistic by hidroh.

the class NavFloatingActionButtonTest method testKonami.

@LooperMode(LooperMode.Mode.LEGACY)
@Test
public void testKonami() {
    // down, invalid, should ignore
    gestureListener.onFling(null, null, 0f, 1f);
    // up
    gestureListener.onFling(null, null, 0f, -1f);
    // down, invalid, should reset
    gestureListener.onFling(null, null, 0f, 1f);
    // up
    gestureListener.onFling(null, null, 0f, -1f);
    // up
    gestureListener.onFling(null, null, 0f, -1f);
    // down
    gestureListener.onFling(null, null, 0f, 1f);
    // down
    gestureListener.onFling(null, null, 0f, 1f);
    // left
    gestureListener.onFling(null, null, -1f, 0f);
    // right
    gestureListener.onFling(null, null, 1f, 0f);
    // left
    gestureListener.onFling(null, null, -1f, 0f);
    // right
    gestureListener.onFling(null, null, 1f, 0f);
    gestureListener.onDoubleTap(null);
    Dialog dialog = ShadowDialog.getLatestDialog();
    assertNotNull(dialog);
    // BUTTON_POSITIVE
    shadowOf(dialog).clickOn(android.R.id.button1);
    assertThat(shadowOf(RuntimeEnvironment.application).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
Also used : ShadowDialog(org.robolectric.shadows.ShadowDialog) Dialog(android.app.Dialog) Test(org.junit.Test) LooperMode(org.robolectric.annotation.LooperMode)

Example 18 with LooperMode

use of org.robolectric.annotation.LooperMode in project prebid-mobile-android by prebid.

the class InterstitialManagerTest method displayViewAsInterstitialSuccess_ShowInterstitialAdView.

@Test
@LooperMode(LooperMode.Mode.PAUSED)
public void displayViewAsInterstitialSuccess_ShowInterstitialAdView() {
    VideoCreative mockVideoCreative = mock(VideoCreative.class);
    when(mockVideoCreative.isResolved()).thenReturn(true);
    BaseJSInterface mockJsInterface = mock(BaseJSInterface.class);
    when(mockJsInterface.getJsExecutor()).thenReturn(mock(JsExecutor.class));
    WebViewBase mockWebViewBase = mock(WebViewBase.class);
    when(mockWebViewBase.getMRAIDInterface()).thenReturn(mockJsInterface);
    PrebidWebViewInterstitial mockPrebidWebViewInterstitial = mock(PrebidWebViewInterstitial.class);
    when(mockPrebidWebViewInterstitial.getWebView()).thenReturn(mockWebViewBase);
    InterstitialView mockInterstitialView = mock(InterstitialView.class);
    when(mockInterstitialView.getCreativeView()).thenReturn(mockPrebidWebViewInterstitial);
    mSpyInterstitialManager.displayAdViewInInterstitial(mContext, mockInterstitialView);
    verify(mMockAdViewDelegate).showInterstitial();
}
Also used : BaseJSInterface(org.prebid.mobile.rendering.views.webview.mraid.BaseJSInterface) PrebidWebViewInterstitial(org.prebid.mobile.rendering.views.webview.PrebidWebViewInterstitial) VideoCreative(org.prebid.mobile.rendering.video.VideoCreative) JsExecutor(org.prebid.mobile.rendering.views.webview.mraid.JsExecutor) WebViewBase(org.prebid.mobile.rendering.views.webview.WebViewBase) InterstitialView(org.prebid.mobile.rendering.bidding.display.InterstitialView) Test(org.junit.Test) LooperMode(org.robolectric.annotation.LooperMode)

Aggregations

LooperMode (org.robolectric.annotation.LooperMode)18 Test (org.junit.Test)15 Scheduler (org.robolectric.util.Scheduler)5 BroadcastReceiver (android.content.BroadcastReceiver)2 Intent (android.content.Intent)2 Handler (android.os.Handler)2 HandlerThread (android.os.HandlerThread)2 Looper (android.os.Looper)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Resetter (org.robolectric.annotation.Resetter)2 ShadowLooper (org.robolectric.shadows.ShadowLooper)2 TestRunnable (org.robolectric.util.TestRunnable)2 Dialog (android.app.Dialog)1 Context (android.content.Context)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 AssumptionViolatedException (org.junit.AssumptionViolatedException)1 InterstitialView (org.prebid.mobile.rendering.bidding.display.InterstitialView)1 VideoCreative (org.prebid.mobile.rendering.video.VideoCreative)1