RemoveView { protected void onMove(final float x, final float y) { if (shouldBeResponsive) { final int midpoint = button.getContext().getResources().getDisplayMetrics().widthPixels / 2; final float xDelta = x - midpoint; final int xTransformed = (int) Math.abs(xDelta * 100 / midpoint); final int bottomPadding = buttonBottomPadding - (xTransformed / 5); if (xDelta < 0) { button.setPadding(0, 0, xTransformed, bottomPadding); } else { button.setPadding(xTransformed, 0, 0, bottomPadding); } } } protected  RemoveView(Context context);   }
@Test public void testOnMoveXBiggerThanMidpoint() { DisplayMetrics displayMetricsMock = mock(DisplayMetrics.class); Resources resourcesMock = mock(Resources.class); doReturn(contextMock).when(buttonMock).getContext(); doReturn(resourcesMock).when(contextMock).getResources(); doReturn(displayMetricsMock).when(resourcesMock).getDisplayMetrics(); displayMetricsMock.widthPixels = 400; int x = 250; int midpoint = displayMetricsMock.widthPixels / 2; int xDelta = x - midpoint; int xTransformed = Math.abs(xDelta * 100 / midpoint); int bottomPadding = buttonBottomPaddingTest - (xTransformed / 5); removeView.onMove(x, 200); verify(buttonMock).setPadding(xTransformed, 0, 0, bottomPadding); }
@Test public void testOnMoveXSmallerThanMidpoint() { DisplayMetrics displayMetricsMock = mock(DisplayMetrics.class); Resources resourcesMock = mock(Resources.class); doReturn(contextMock).when(buttonMock).getContext(); doReturn(resourcesMock).when(contextMock).getResources(); doReturn(displayMetricsMock).when(resourcesMock).getDisplayMetrics(); displayMetricsMock.widthPixels = 400; int x = 100; int midpoint = displayMetricsMock.widthPixels / 2; int xDelta = x - midpoint; int xTransformed = Math.abs(xDelta * 100 / midpoint); int bottomPadding = buttonBottomPaddingTest - (xTransformed / 5); removeView.onMove(x, 100); verify(buttonMock).setPadding(0, 0, xTransformed, bottomPadding); }