org.mockito.Mockito.anyFloat()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(15.8k)|赞(0)|评价(0)|浏览(166)

本文整理了Java中org.mockito.Mockito.anyFloat()方法的一些代码示例,展示了Mockito.anyFloat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.anyFloat()方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:anyFloat

Mockito.anyFloat介绍

暂无

代码示例

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_dragRightInRightEnd_ignoreTouchEvent() throws Exception {
  // Arrange
  MotionEvent event = createShortRightMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(false);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(true);
  HorizontalOverScrollBounceEffectDecorator uut = getUUT();
  // Act
  boolean ret = uut.onTouch(mView, event);
  // Assert
  verify(mView, never()).setTranslationX(anyFloat());
  verify(mView, never()).setTranslationY(anyFloat());
  assertFalse(ret);
  assertEquals(STATE_IDLE, uut.getCurrentState());
  verify(mStateListener, never()).onOverScrollStateChange(eq(uut), anyInt(), anyInt());
  verify(mUpdateListener, never()).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchUpAction_eventWhenNotOverscrolled_ignoreTouchEvent() throws Exception {
  // Arrange
  MotionEvent event = createDefaultUpActionEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(true);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(true);
  HorizontalOverScrollBounceEffectDecorator uut = getUUT();
  // Act
  boolean ret = uut.onTouch(mView, event);
  // Assert
  verify(mView, never()).setTranslationX(anyFloat());
  verify(mView, never()).setTranslationY(anyFloat());
  assertFalse(ret);
  assertEquals(STATE_IDLE, uut.getCurrentState());
  verify(mStateListener, never()).onOverScrollStateChange(eq(uut), anyInt(), anyInt());
  verify(mUpdateListener, never()).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_dragUpInUpperEnd_ignoreTouchEvent() throws Exception {
  // Arrange
  MotionEvent event = createShortUpwardsMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(true);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(false);
  VerticalOverScrollBounceEffectDecorator uut = getUUT();
  // Act
  boolean ret = uut.onTouch(mView, event);
  // Assert
  verify(mView, never()).setTranslationX(anyFloat());
  verify(mView, never()).setTranslationY(anyFloat());
  assertFalse(ret);
  assertEquals(STATE_IDLE, uut.getCurrentState());
  verify(mStateListener, never()).onOverScrollStateChange(eq(uut), anyInt(), anyInt());
  verify(mUpdateListener, never()).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_dragLeftInLeftEnd_ignoreTouchEvent() throws Exception {
  // Arrange
  MotionEvent event = createShortLeftMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(true);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(false);
  HorizontalOverScrollBounceEffectDecorator uut = getUUT();
  // Act
  final boolean ret = uut.onTouch(mView, event);
  // Assert
  verify(mView, never()).setTranslationX(anyFloat());
  verify(mView, never()).setTranslationY(anyFloat());
  assertFalse(ret);
  assertEquals(STATE_IDLE, uut.getCurrentState());
  verify(mStateListener, never()).onOverScrollStateChange(eq(uut), anyInt(), anyInt());
  verify(mUpdateListener, never()).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_notInViewEnds_ignoreTouchEvent() throws Exception {
  // Arrange
  MotionEvent event = createShortDownwardsMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(false);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(false);
  VerticalOverScrollBounceEffectDecorator uut = getUUT();
  // Act
  boolean ret = uut.onTouch(mView, event);
  // Assert
  verify(mView, never()).setTranslationX(anyFloat());
  verify(mView, never()).setTranslationY(anyFloat());
  assertFalse(ret);
  assertEquals(STATE_IDLE, uut.getCurrentState());
  verify(mStateListener, never()).onOverScrollStateChange(eq(uut),anyInt(), anyInt());
  verify(mUpdateListener, never()).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_dragDownInBottomEnd_ignoreTouchEvent() throws Exception {
  // Arrange
  MotionEvent event = createShortDownwardsMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(false);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(true);
  VerticalOverScrollBounceEffectDecorator uut = getUUT();
  // Act
  boolean ret = uut.onTouch(mView, event);
  // Assert
  verify(mView, never()).setTranslationX(anyFloat());
  verify(mView, never()).setTranslationY(anyFloat());
  assertFalse(ret);
  assertEquals(STATE_IDLE, uut.getCurrentState());
  verify(mStateListener, never()).onOverScrollStateChange(eq(uut), anyInt(), anyInt());
  verify(mUpdateListener, never()).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchUpAction_eventWhenNotOverscrolled_ignoreTouchEvent() throws Exception {
  // Arrange
  MotionEvent event = createDefaultUpActionEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(true);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(true);
  VerticalOverScrollBounceEffectDecorator uut = getUUT();
  // Act
  boolean ret = uut.onTouch(mView, event);
  // Assert
  verify(mView, never()).setTranslationX(anyFloat());
  verify(mView, never()).setTranslationY(anyFloat());
  assertFalse(ret);
  assertEquals(STATE_IDLE, uut.getCurrentState());
  verify(mStateListener, never()).onOverScrollStateChange(eq(uut), anyInt(), anyInt());
  verify(mUpdateListener, never()).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_notInViewEnds_ignoreTouchEvent() throws Exception {
  // Arrange
  MotionEvent event = createShortRightMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(false);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(false);
  HorizontalOverScrollBounceEffectDecorator uut = getUUT();
  // Act
  boolean ret = uut.onTouch(mView, event);
  // Assert
  verify(mView, never()).setTranslationX(anyFloat());
  verify(mView, never()).setTranslationY(anyFloat());
  assertFalse(ret);
  assertEquals(STATE_IDLE, uut.getCurrentState());
  verify(mStateListener, never()).onOverScrollStateChange(eq(uut), anyInt(), anyInt());
  verify(mUpdateListener, never()).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_dragDownInUpperEnd_overscrollDownwards() throws Exception {
  // Arrange
  MotionEvent event = createShortDownwardsMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(true);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(false);
  VerticalOverScrollBounceEffectDecorator uut = getUUT();
  // Act
  boolean ret = uut.onTouch(mView, event);
  // Assert
  float expectedTransY = (event.getY() - event.getHistoricalY(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
  verify(mView).setTranslationY(expectedTransY);
  verify(mView, never()).setTranslationX(anyFloat());
  assertTrue(ret);
  assertEquals(STATE_DRAG_START_SIDE, uut.getCurrentState());
  verify(mStateListener).onOverScrollStateChange(eq(uut), eq(STATE_IDLE), eq(STATE_DRAG_START_SIDE));
  verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_START_SIDE), eq(expectedTransY));
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_dragLeftInRightEnd_overscrollLeft() throws Exception {
  // Arrange
  MotionEvent event = createShortLeftMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(false);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(true);
  HorizontalOverScrollBounceEffectDecorator uut = getUUT();
  // Act
  final boolean ret = uut.onTouch(mView, event);
  // Assert
  final float expectedTransX = (event.getX() - event.getHistoricalX(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
  verify(mView).setTranslationX(expectedTransX);
  verify(mView, never()).setTranslationY(anyFloat());
  assertTrue(ret);
  assertEquals(STATE_DRAG_END_SIDE, uut.getCurrentState());
  verify(mStateListener).onOverScrollStateChange(eq(uut), eq(STATE_IDLE), eq(STATE_DRAG_END_SIDE));
  verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_END_SIDE), eq(expectedTransX));
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_dragUpInBottomEnd_overscrollUpwards() throws Exception {
  // Arrange
  MotionEvent event = createShortUpwardsMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(false);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(true);
  VerticalOverScrollBounceEffectDecorator uut = getUUT();
  // Act
  boolean ret = uut.onTouch(mView, event);
  // Assert
  float expectedTransY = (event.getY() - event.getHistoricalY(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
  verify(mView).setTranslationY(expectedTransY);
  verify(mView, never()).setTranslationX(anyFloat());
  assertTrue(ret);
  assertEquals(STATE_DRAG_END_SIDE, uut.getCurrentState());
  verify(mStateListener).onOverScrollStateChange(eq(uut), eq(STATE_IDLE), eq(STATE_DRAG_END_SIDE));
  verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_END_SIDE), eq(expectedTransY));
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_dragRightInLeftEnd_overscrollRight() throws Exception {
  // Arrange
  MotionEvent event = createShortRightMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(true);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(false);
  HorizontalOverScrollBounceEffectDecorator uut = getUUT();
  // Act
  final boolean ret = uut.onTouch(mView, event);
  // Assert
  final float expectedTransX = (event.getX() - event.getHistoricalX(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
  verify(mView).setTranslationX(expectedTransX);
  verify(mView, never()).setTranslationY(anyFloat());
  assertTrue(ret);
  assertEquals(STATE_DRAG_START_SIDE, uut.getCurrentState());
  verify(mStateListener).onOverScrollStateChange(eq(uut), eq(STATE_IDLE), eq(STATE_DRAG_START_SIDE));
  verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_START_SIDE), eq(expectedTransX));
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_2ndRightDragInLeftEnd_overscrollRightFurther() throws Exception {
  // Arrange
  // Bring UUT to a right-overscroll state
  MotionEvent event1 = createShortRightMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(true);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(false);
  HorizontalOverScrollBounceEffectDecorator uut = getUUT();
  uut.onTouch(mView, event1);
  reset(mView);
  // Create 2nd right-drag event
  MotionEvent event2 = createLongRightMoveEvent();
  // Act
  final boolean ret = uut.onTouch(mView, event2);
  // Assert
  final float expectedTransX1 = (event1.getX() - event1.getHistoricalX(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
  final float expectedTransX2 = (event2.getX() - event2.getHistoricalX(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
  verify(mView).setTranslationX(expectedTransX2);
  verify(mView, never()).setTranslationY(anyFloat());
  assertTrue(ret);
  assertEquals(STATE_DRAG_START_SIDE, uut.getCurrentState());
  // State-change listener called only once?
  verify(mStateListener).onOverScrollStateChange(eq(uut), eq(STATE_IDLE), eq(STATE_DRAG_START_SIDE));
  verify(mStateListener).onOverScrollStateChange(eq(uut), anyInt(), anyInt());
  // Update-listener called exactly twice?
  verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_START_SIDE), eq(expectedTransX1));
  verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_START_SIDE), eq(expectedTransX2));
  verify(mUpdateListener, times(2)).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}

代码示例来源:origin: EverythingMe/overscroll-decor

verify(mView, never()).setTranslationY(anyFloat());
assertTrue(ret);
assertEquals(STATE_IDLE, uut.getCurrentState());
verify(mUpdateListener, times(2)).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());

代码示例来源:origin: EverythingMe/overscroll-decor

verify(mView, never()).setTranslationY(anyFloat());
assertTrue(ret);
assertEquals(STATE_IDLE, uut.getCurrentState());
verify(mUpdateListener, times(2)).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());

代码示例来源:origin: EverythingMe/overscroll-decor

verify(mView, never()).setTranslationY(anyFloat());
assertTrue(ret);
assertEquals(STATE_DRAG_END_SIDE, uut.getCurrentState());
verify(mUpdateListener, times(2)).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_2ndDownDragInUpperEnd_overscrollDownwardsFurther() throws Exception {
  // Arrange
  // Bring UUT to a downwards-overscroll state
  MotionEvent event1 = createShortDownwardsMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(true);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(false);
  VerticalOverScrollBounceEffectDecorator uut = getUUT();
  uut.onTouch(mView, event1);
  reset(mView);
  // Create 2nd downwards-drag event
  MotionEvent event2 = createLongDownwardsMoveEvent();
  // Act
  final boolean ret = uut.onTouch(mView, event2);
  // Assert
  final float expectedTransY1 = (event1.getY() - event1.getHistoricalY(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
  final float expectedTransY2 = (event2.getY() - event2.getHistoricalY(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
  verify(mView).setTranslationY(expectedTransY2);
  verify(mView, never()).setTranslationX(anyFloat());
  assertTrue(ret);
  assertEquals(STATE_DRAG_START_SIDE, uut.getCurrentState());
  // State-change listener called only once?
  verify(mStateListener).onOverScrollStateChange(eq(uut), eq(STATE_IDLE), eq(STATE_DRAG_START_SIDE));
  verify(mStateListener).onOverScrollStateChange(eq(uut), anyInt(), anyInt());
  // Update-listener called exactly twice?
  verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_START_SIDE), eq(expectedTransY1));
  verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_START_SIDE), eq(expectedTransY2));
  verify(mUpdateListener, times(2)).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Test
public void onTouchMoveAction_2ndUpDragInBottomEnd_overscrollUpwardsFurther() throws Exception {
  // Arrange
  // Bring UUT to an upwards-overscroll state
  MotionEvent event1 = createShortUpwardsMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(false);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(true);
  VerticalOverScrollBounceEffectDecorator uut = getUUT();
  uut.onTouch(mView, event1);
  reset(mView);
  // Create 2nd upward-drag event
  MotionEvent event2 = createLongUpwardsMoveEvent();
  // Act
  final boolean ret = uut.onTouch(mView, event2);
  // Assert
  final float expectedTransY1 = (event1.getY() - event1.getHistoricalY(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
  final float expectedTransY2 = (event2.getY() - event2.getHistoricalY(0)) / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
  verify(mView).setTranslationY(expectedTransY2);
  verify(mView, never()).setTranslationX(anyFloat());
  assertTrue(ret);
  assertEquals(STATE_DRAG_END_SIDE, uut.getCurrentState());
  // State-change listener called only once?
  verify(mStateListener).onOverScrollStateChange(eq(uut), eq(STATE_IDLE), eq(STATE_DRAG_END_SIDE));
  verify(mStateListener).onOverScrollStateChange(eq(uut), anyInt(), anyInt());
  // Update-listener called exactly twice?
  verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_END_SIDE), eq(expectedTransY1));
  verify(mUpdateListener).onOverScrollUpdate(eq(uut), eq(STATE_DRAG_END_SIDE), eq(expectedTransY2));
  verify(mUpdateListener, times(2)).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());
}

代码示例来源:origin: EverythingMe/overscroll-decor

(eventMoveLeft.getX() - eventMoveLeft.getHistoricalX(0)) / touchDragRatioBck;
verify(mView).setTranslationX(expectedTransX);
verify(mView, never()).setTranslationY(anyFloat());
assertTrue(ret);
assertEquals(STATE_DRAG_START_SIDE, uut.getCurrentState());
verify(mUpdateListener, times(2)).onOverScrollUpdate(eq(uut), anyInt(), anyFloat());

代码示例来源:origin: EverythingMe/overscroll-decor

/**
 * TODO: Make this work using a decent animation shadows / newer Robolectric
 * @throws Exception
 */
@Ignore
@Test
public void onTouchUpAction_eventWhenLeftOverscrolling_smoothScrollBackToRightEnd() throws Exception {
  // Arrange
  // Bring UUT to a left-overscroll state
  MotionEvent moveEvent = createShortLeftMoveEvent();
  when(mViewAdapter.isInAbsoluteStart()).thenReturn(false);
  when(mViewAdapter.isInAbsoluteEnd()).thenReturn(true);
  HorizontalOverScrollBounceEffectDecorator uut = getUUT();
  uut.onTouch(mView, moveEvent);
  reset(mView);
  // Make the view as though it's been moved by the move event
  float viewX = moveEvent.getX();
  when(mView.getTranslationX()).thenReturn(viewX);
  MotionEvent upEvent = createDefaultUpActionEvent();
  // Act
  boolean ret = uut.onTouch(mView, upEvent);
  // Assert
  assertTrue(ret);
  verify(mView, atLeastOnce()).setTranslationX(anyFloat());
}

相关文章