AdAlertGestureListener extends GestureDetector.SimpleOnGestureListener { @Deprecated int getNumberOfZigzags() { return mNumberOfZigZags; } AdAlertGestureListener(View view, @Nullable AdReport adReport); @Override boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY);  }
@Test public void onScroll_withInitialLeftThenRightMovement_BeforeZigCompletes_MovesOutOfUpperYBounds_shouldSetStateToFailed() throws Exception { simulateScroll(INITIAL_X); assertZigZagState(UNSET); simulateScroll(INITIAL_X + 10); assertZigZagState(GOING_RIGHT); simulateScroll(savedX, INITIAL_Y + 49); assertZigZagState(GOING_RIGHT); assertThat(subject.getNumberOfZigzags()).isEqualTo(0); simulateScroll(savedX, INITIAL_Y + 102); assertZigZagState(FAILED); }
@Test public void onScroll_withInitialLeftThenRightMovement_BeforeZigCompletes_MovesOutOfLowerYBounds_shouldSetStateToFailed() throws Exception { simulateScroll(INITIAL_X); assertZigZagState(UNSET); simulateScroll(INITIAL_X + 10); assertZigZagState(GOING_RIGHT); simulateScroll(savedX, INITIAL_Y - 49); assertZigZagState(GOING_RIGHT); assertThat(subject.getNumberOfZigzags()).isEqualTo(0); simulateScroll(savedX, INITIAL_Y - 101); assertZigZagState(FAILED); }
@Test public void onScroll_withZigZagZigZagZigZagZig_BeforeNextZagCompletes_MovesOutOfUpperYBounds_shouldSetStateToFailed() throws Exception { performZigZag(); performZigZag(); performZigZag(); performZig(); simulateScroll(savedX, INITIAL_Y + 49); assertZigZagState(GOING_RIGHT); assertThat(subject.getNumberOfZigzags()).isEqualTo(3); simulateScroll(savedX, INITIAL_Y + 101); assertZigZagState(FAILED); }
@Test public void onScroll_withZigZagZigZagZigZagZig_BeforeNextZagCompletes_MovesOutOfLowerYBounds_shouldSetStateToFailed() throws Exception { performZigZag(); performZigZag(); performZigZag(); performZig(); simulateScroll(savedX - 1, INITIAL_Y - 49); assertZigZagState(GOING_LEFT); assertThat(subject.getNumberOfZigzags()).isEqualTo(3); simulateScroll(savedX, INITIAL_Y - 101); assertZigZagState(FAILED); }
@Test public void onScroll_withCompleteZigZag_shouldSetStateToGoingLeftAndNumberOfZigZagsIs1() throws Exception { performZig(); assertZigZagState(GOING_RIGHT); assertThat(subject.getNumberOfZigzags()).isEqualTo(0); performZag(); assertZigZagState(GOING_LEFT); assertThat(subject.getNumberOfZigzags()).isEqualTo(1); }
@Test public void onScroll_withZig_butBeforeZagIsComplete_shouldKeepStateGoingLeftButNotIncrementZigZags() throws Exception { performZig(); assertZigZagState(GOING_RIGHT); simulateScroll(INITIAL_X + threshold - 5); assertZigZagState(GOING_LEFT); simulateScroll(INITIAL_X + threshold); assertZigZagState(GOING_LEFT); assertThat(subject.getNumberOfZigzags()).isEqualTo(0); }
@Test public void onScroll_withFourZigZags_shouldSetStateToFinished() throws Exception { performZigZag(); assertThat(subject.getNumberOfZigzags()).isEqualTo(1); performZigZag(); assertThat(subject.getNumberOfZigzags()).isEqualTo(2); performZigZag(); assertThat(subject.getNumberOfZigzags()).isEqualTo(3); performZigZag(); assertThat(subject.getNumberOfZigzags()).isEqualTo(4); assertZigZagState(FINISHED); }