ViewGestureDetector extends GestureDetector { public void sendTouchEvent(MotionEvent motionEvent) { switch (motionEvent.getAction()) { case MotionEvent.ACTION_UP: if (mUserClickListener != null) { mUserClickListener.onUserClick(); } else { MoPubLog.d("View's onUserClick() is not registered."); } mAdAlertGestureListener.finishGestureDetection(); break; case MotionEvent.ACTION_DOWN: onTouchEvent(motionEvent); break; case MotionEvent.ACTION_MOVE: if (isMotionEventInView(motionEvent, mView)) { onTouchEvent(motionEvent); } else { resetAdFlaggingGesture(); } break; default: break; } } ViewGestureDetector(@NonNull Context context, @NonNull View view, @Nullable AdReport adReport); private  ViewGestureDetector(Context context, View view, AdAlertGestureListener adAlertGestureListener); void sendTouchEvent(MotionEvent motionEvent); void setUserClickListener(UserClickListener listener);  }
@Test public void onTouchEvent_whenActionUpButNoClickListener_shouldNotNotifyClickListenerAndCheckReportAd() throws Exception { MotionEvent expectedMotionEvent = createMotionEvent(MotionEvent.ACTION_UP); UserClickListener userClickListener = mock(UserClickListener.class); subject.sendTouchEvent(expectedMotionEvent); verify(userClickListener, never()).onUserClick(); verify(adAlertGestureListener).finishGestureDetection(); }
@Test public void onTouchEvent_whenActionDown_shouldForwardOnTouchEvent() throws Exception { MotionEvent expectedMotionEvent = createMotionEvent(MotionEvent.ACTION_DOWN); subject.sendTouchEvent(expectedMotionEvent); MotionEvent actualMotionEvent = shadowOf(subject).getOnTouchEventMotionEvent(); assertThat(actualMotionEvent).isEqualTo(expectedMotionEvent); }
@Test public void onTouchEvent_whenActionMoveWithinView_shouldForwardOnTouchEvent() throws Exception { MotionEvent expectedMotionEvent = createActionMove(160); subject.sendTouchEvent(expectedMotionEvent); MotionEvent actualMotionEvent = shadowOf(subject).getOnTouchEventMotionEvent(); assertThat(actualMotionEvent).isEqualTo(expectedMotionEvent); verify(adAlertGestureListener, never()).reset(); }
@Test public void sendTouchEvent_whenReceiveTouchEventOutsideOfViewInXDirection_shouldResetAlertState() throws Exception { subject.sendTouchEvent(createActionMove(350)); MotionEvent actualMotionEvent = shadowOf(subject).getOnTouchEventMotionEvent(); assertThat(actualMotionEvent).isNull(); verify(adAlertGestureListener).reset(); }
@Test public void sendTouchEvent_whenReceiveTouchEventOutsideOfViewInYDirection_shouldResetAlertState() throws Exception { MotionEvent verticalMotion = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 160, 200, 0); subject.sendTouchEvent(verticalMotion); MotionEvent actualMotionEvent = shadowOf(subject).getOnTouchEventMotionEvent(); assertThat(actualMotionEvent).isNull(); verify(adAlertGestureListener).reset(); }