If you think the Android project ListViewAnimations listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2014 Niek Haarman//fromwww.java2s.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.nhaarman.listviewanimations.itemmanipulation.dragdrop;
import android.content.Context;
import android.test.AndroidTestCase;
import android.view.MotionEvent;
import android.view.View;
import org.mockito.*;
importstatic org.hamcrest.MatcherAssert.*;
importstatic org.hamcrest.Matchers.*;
@SuppressWarnings("ALL")
publicclass HoverDrawableTest extends AndroidTestCase {
privatestaticfinalint START_Y = 29;
private HoverDrawable mHoverDrawable;
private View mView;
@Override
protectedvoid setUp() throws Exception {
super.setUp();
MockitoAnnotations.initMocks(this);
mView = new MyMockView(getContext());
mView.measure(0, 0);
mHoverDrawable = new HoverDrawable(mView, START_Y);
}
publicvoid testInitialState() {
assertThat(mHoverDrawable.getDeltaY(), is(0));
assertThat(mHoverDrawable.getBounds().top, is(0));
assertThat(mHoverDrawable.isMovingUpwards(), is(false));
}
publicvoid testMovedState() {
MotionEvent motionEvent = createMotionEvent(START_Y + 10);
mHoverDrawable.handleMoveEvent(motionEvent);
assertThat(mHoverDrawable.getDeltaY(), is(10));
assertThat(mHoverDrawable.getBounds().top, is(10));
assertThat(mHoverDrawable.isMovingUpwards(), is(false));
}
publicvoid testDoubleMovedState() {
MotionEvent motionEvent = createMotionEvent(START_Y + 10);
mHoverDrawable.handleMoveEvent(motionEvent);
MotionEvent motionEvent2 = createMotionEvent(START_Y + 20);
mHoverDrawable.handleMoveEvent(motionEvent2);
assertThat(mHoverDrawable.getDeltaY(), is(20));
assertThat(mHoverDrawable.getBounds().top, is(20));
assertThat(mHoverDrawable.isMovingUpwards(), is(false));
}
publicvoid testReversedMovedState() {
MotionEvent motionEvent = createMotionEvent(START_Y - 10);
mHoverDrawable.handleMoveEvent(motionEvent);
assertThat(mHoverDrawable.getDeltaY(), is(-10));
assertThat(mHoverDrawable.getBounds().top, is(-10));
assertThat(mHoverDrawable.isMovingUpwards(), is(true));
}
publicvoid testReversedDoubleMovedState() {
MotionEvent motionEvent = createMotionEvent(START_Y - 10);
mHoverDrawable.handleMoveEvent(motionEvent);
MotionEvent motionEvent2 = createMotionEvent(START_Y - 20);
mHoverDrawable.handleMoveEvent(motionEvent2);
assertThat(mHoverDrawable.getDeltaY(), is(-20));
assertThat(mHoverDrawable.getBounds().top, is(-20));
assertThat(mHoverDrawable.isMovingUpwards(), is(true));
}
publicvoid testShift() {
MotionEvent motionEvent = createMotionEvent(START_Y - 10);
mHoverDrawable.handleMoveEvent(motionEvent);
mHoverDrawable.shift(10);
assertThat(mHoverDrawable.getDeltaY(), is(0));
assertThat(mHoverDrawable.isMovingUpwards(), is(false));
assertThat(mHoverDrawable.getBounds().top, is(-10));
}
publicvoid testScroll() {
mHoverDrawable.onScroll(20);
assertThat(mHoverDrawable.getDeltaY(), is(-20));
assertThat(mHoverDrawable.isMovingUpwards(), is(true));
assertThat(mHoverDrawable.getBounds().top, is(0));
}
privatestatic MotionEvent createMotionEvent(finalfloat y) {
return MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, y, 0);
}
privatestaticclass MyMockView extends View {
MyMockView(final Context context) {
super(context);
}
@Override
protectedvoid onMeasure(finalint widthMeasureSpec, finalint heightMeasureSpec) {
setMeasuredDimension(100, 100);
}
}
}