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/*www.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.support.annotation.NonNull;
import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import com.nhaarman.listviewanimations.itemmanipulation.DynamicListView;
import org.mockito.*;
importstatic org.mockito.Mockito.*;
publicclass DynamicListViewDragAndDropTest extends ActivityInstrumentationTestCase2<DynamicListViewTestActivity> {
private DynamicListView mDynamicListView;
@Mock
private OnItemMovedListener mOnItemMovedListener;
public DynamicListViewDragAndDropTest() {
super(DynamicListViewTestActivity.class);
}
@Override
publicvoid setUp() throws Exception, InterruptedException {
super.setUp();
MockitoAnnotations.initMocks(this);
mDynamicListView = getActivity().getDynamicListView();
mDynamicListView.enableDragAndDrop();
mDynamicListView.setDraggableManager(new MyDraggableManager());
mDynamicListView.setOnItemMovedListener(mOnItemMovedListener);
getInstrumentation().waitForIdleSync();
Thread.sleep(5000);
}
publicvoid testOnItemMovedListenerCalled() throws InterruptedException {
MotionEventUtils.dispatchDragMotionEvents(getInstrumentation(), mDynamicListView, 0, 1);
verify(mOnItemMovedListener).onItemMoved(0, 1);
}
publicvoid testReverseOnItemMovedListenerCalled() throws InterruptedException {
MotionEventUtils.dispatchDragMotionEvents(getInstrumentation(), mDynamicListView, 2, 1);
verify(mOnItemMovedListener).onItemMoved(2, 1);
}
publicvoid testOnItemMovedListenerCalledMultipleItems() throws InterruptedException {
MotionEventUtils.dispatchDragMotionEvents(getInstrumentation(), mDynamicListView, 1, 5);
verify(mOnItemMovedListener).onItemMoved(1, 5);
}
publicvoid testScroll() throws InterruptedException {
MotionEventUtils.dispatchDragScrollDownMotionEvents(getInstrumentation(), mDynamicListView, 1);
verify(mOnItemMovedListener).onItemMoved(1, 19);
}
privatestaticclass MyDraggableManager implements DraggableManager {
@Override
publicboolean isDraggable(@NonNull final View view, finalint position, finalfloat x, finalfloat y) {
return true;
}
}
}