// Path: lib-manipulation/src/androidTest/java/com/nhaarman/listviewanimations/itemmanipulation/swipedismiss/SwipeTouchListenerTestActivity.java
// public class SwipeTouchListenerTestActivity extends Activity {
// 
//     private ListView mListView;
// 
//     @Override
//     protected void onCreate(final Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
// 
//         Window window = getWindow();
//         window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
// 
//         mListView = new ListView(this);
//         List<Integer> integers = new ArrayList<Integer>();
//         for (int i = 0; i < 20; i++) {
//             integers.add(i);
//         }
// 
//         ListAdapter myListAdapter = new MyListAdapter(this, integers);
//         mListView.setAdapter(myListAdapter);
// 
//         setContentView(mListView);
//     }
// 
//     @Override
//     public boolean dispatchTouchEvent(MotionEvent ev) {
//         int[] location = new int[2];
//         mListView.getLocationOnScreen(location);
// 
//         ev = MotionEvent.obtain(ev.getDownTime(), ev.getEventTime(), ev.getAction(), ev.getX() - location[0], ev.getY() - location[1], ev.getMetaState());
//         boolean handled = mListView.onInterceptTouchEvent(ev);
//         if (!handled) {
//             handled = mListView.dispatchTouchEvent(ev);
//         }
//         if (!handled) {
//             handled = onTouchEvent(ev);
//         }
//         return handled;
//     }
// 
//     public AbsListView getAbsListView() {
//         return mListView;
//     }
// 
//     private static class MyListAdapter extends ArrayAdapter<Integer> {
// 
//         private final Context mContext;
// 
//         MyListAdapter(final Context context, final List<Integer> items) {
//             super(items);
//             mContext = context;
//         }
// 
//         @Override
//         public long getItemId(final int location) {
//             return getItem(location).hashCode();
//         }
// 
//         @Override
//         public boolean hasStableIds() {
//             return true;
//         }
// 
//         @Override
//         public View getView(final int position, final View convertView, final ViewGroup parent) {
//             TextView view = (TextView) convertView;
//             if (view == null) {
//                 view = new TextView(mContext);
//                 view.setTextSize(30);
//             }
// 
//             view.setText("This is row number " + getItem(position));
//             return view;
//         }
//     }
// }
// 
// Path: lib-manipulation/src/androidTest/java/com/nhaarman/listviewanimations/itemmanipulation/swipedismiss/MotionEventUtils.java
// public static void dispatchSwipeMotionEvents(final Instrumentation instrumentation, final AbsListView absListView, final int position) throws InterruptedException {
//     dispatchMotionEvents(instrumentation, createSwipeMotionEvents(absListView, position));
// }
// 
// Path: lib-manipulation/src/androidTest/java/com/nhaarman/listviewanimations/itemmanipulation/swipedismiss/MotionEventUtils.java
// public static void dispatchSwipeMotionEventsAndWait(final Instrumentation instrumentation, final AbsListView absListView, final int position) throws InterruptedException {
//     dispatchMotionEventsAndWait(instrumentation, createSwipeMotionEvents(absListView, position));
// }


import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import android.widget.AbsListView;
import com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.SwipeTouchListenerTestActivity;
import com.nhaarman.listviewanimations.util.AbsListViewWrapper;
import org.mockito.*;
import static com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.MotionEventUtils.dispatchSwipeMotionEvents;
import static com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.MotionEventUtils.dispatchSwipeMotionEventsAndWait;
import static org.mockito.AdditionalMatchers.*;
import static org.mockito.Mockito.*;
/*
 * Copyright 2014 Niek Haarman
 *
 * 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.swipedismiss.undo;





public class SwipeUndoTouchListenerTest extends ActivityInstrumentationTestCase2<SwipeTouchListenerTestActivity> {

    /**
     * An Activity hosting a ListView with items.
     */
    private SwipeTouchListenerTestActivity mActivity;

    /**
     * The AbsListView that is hosted in mActivity.
     */
    private AbsListView mAbsListView;

    @Mock
    private UndoCallback mUndoCallback;

    private SwipeUndoTouchListener mSwipeUndoTouchListener;


    public SwipeUndoTouchListenerTest() {
        super(SwipeTouchListenerTestActivity.class);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();

        MockitoAnnotations.initMocks(this);
        when(mUndoCallback.getUndoView(any(View.class))).thenReturn(new View(getActivity()));
        when(mUndoCallback.getPrimaryView(any(View.class))).thenReturn(new View(getActivity()));

        mActivity = getActivity();
        mAbsListView = mActivity.getAbsListView();

        mSwipeUndoTouchListener = new SwipeUndoTouchListener(new AbsListViewWrapper(mAbsListView), mUndoCallback);
        mAbsListView.setOnTouchListener(mSwipeUndoTouchListener);

        getInstrumentation().waitForIdleSync();
    }

    /**
     * Tests whether swiping an item once triggers UndoCallback#onUndoShown.
     */
    public void testUndoShown() throws InterruptedException {
        dispatchSwipeMotionEventsAndWait(getInstrumentation(), mAbsListView, 0);

        verify(mUndoCallback).onUndoShown(any(View.class), eq(0));
    }

    /**
     * Tests whether swiping an item twice triggers UndoCallback#onDismiss.
     */
// Path: lib-manipulation/src/androidTest/java/com/nhaarman/listviewanimations/itemmanipulation/swipedismiss/SwipeTouchListenerTestActivity.java
// public class SwipeTouchListenerTestActivity extends Activity {
// 
//     private ListView mListView;
// 
//     @Override
//     protected void onCreate(final Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
// 
//         Window window = getWindow();
//         window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
// 
//         mListView = new ListView(this);
//         List<Integer> integers = new ArrayList<Integer>();
//         for (int i = 0; i < 20; i++) {
//             integers.add(i);
//         }
// 
//         ListAdapter myListAdapter = new MyListAdapter(this, integers);
//         mListView.setAdapter(myListAdapter);
// 
//         setContentView(mListView);
//     }
// 
//     @Override
//     public boolean dispatchTouchEvent(MotionEvent ev) {
//         int[] location = new int[2];
//         mListView.getLocationOnScreen(location);
// 
//         ev = MotionEvent.obtain(ev.getDownTime(), ev.getEventTime(), ev.getAction(), ev.getX() - location[0], ev.getY() - location[1], ev.getMetaState());
//         boolean handled = mListView.onInterceptTouchEvent(ev);
//         if (!handled) {
//             handled = mListView.dispatchTouchEvent(ev);
//         }
//         if (!handled) {
//             handled = onTouchEvent(ev);
//         }
//         return handled;
//     }
// 
//     public AbsListView getAbsListView() {
//         return mListView;
//     }
// 
//     private static class MyListAdapter extends ArrayAdapter<Integer> {
// 
//         private final Context mContext;
// 
//         MyListAdapter(final Context context, final List<Integer> items) {
//             super(items);
//             mContext = context;
//         }
// 
//         @Override
//         public long getItemId(final int location) {
//             return getItem(location).hashCode();
//         }
// 
//         @Override
//         public boolean hasStableIds() {
//             return true;
//         }
// 
//         @Override
//         public View getView(final int position, final View convertView, final ViewGroup parent) {
//             TextView view = (TextView) convertView;
//             if (view == null) {
//                 view = new TextView(mContext);
//                 view.setTextSize(30);
//             }
// 
//             view.setText("This is row number " + getItem(position));
//             return view;
//         }
//     }
// }
// 
// Path: lib-manipulation/src/androidTest/java/com/nhaarman/listviewanimations/itemmanipulation/swipedismiss/MotionEventUtils.java
// public static void dispatchSwipeMotionEvents(final Instrumentation instrumentation, final AbsListView absListView, final int position) throws InterruptedException {
//     dispatchMotionEvents(instrumentation, createSwipeMotionEvents(absListView, position));
// }
// 
// Path: lib-manipulation/src/androidTest/java/com/nhaarman/listviewanimations/itemmanipulation/swipedismiss/MotionEventUtils.java
// public static void dispatchSwipeMotionEventsAndWait(final Instrumentation instrumentation, final AbsListView absListView, final int position) throws InterruptedException {
//     dispatchMotionEventsAndWait(instrumentation, createSwipeMotionEvents(absListView, position));
// }


// Path: lib-manipulation/src/androidTest/java/com/nhaarman/listviewanimations/itemmanipulation/swipedismiss/undo/SwipeUndoTouchListenerTest.java
import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import android.widget.AbsListView;
import com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.SwipeTouchListenerTestActivity;
import com.nhaarman.listviewanimations.util.AbsListViewWrapper;
import org.mockito.*;
import static com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.MotionEventUtils.dispatchSwipeMotionEvents;
import static com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.MotionEventUtils.dispatchSwipeMotionEventsAndWait;
import static org.mockito.AdditionalMatchers.*;
import static org.mockito.Mockito.*;

/*
 * Copyright 2014 Niek Haarman
 *
 * 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.swipedismiss.undo;





public class SwipeUndoTouchListenerTest extends ActivityInstrumentationTestCase2<SwipeTouchListenerTestActivity> {

    /**
     * An Activity hosting a ListView with items.
     */
    private SwipeTouchListenerTestActivity mActivity;

    /**
     * The AbsListView that is hosted in mActivity.
     */
    private AbsListView mAbsListView;

    @Mock
    private UndoCallback mUndoCallback;

    private SwipeUndoTouchListener mSwipeUndoTouchListener;


    public SwipeUndoTouchListenerTest() {
        super(SwipeTouchListenerTestActivity.class);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();

        MockitoAnnotations.initMocks(this);
        when(mUndoCallback.getUndoView(any(View.class))).thenReturn(new View(getActivity()));
        when(mUndoCallback.getPrimaryView(any(View.class))).thenReturn(new View(getActivity()));

        mActivity = getActivity();
        mAbsListView = mActivity.getAbsListView();

        mSwipeUndoTouchListener = new SwipeUndoTouchListener(new AbsListViewWrapper(mAbsListView), mUndoCallback);
        mAbsListView.setOnTouchListener(mSwipeUndoTouchListener);

        getInstrumentation().waitForIdleSync();
    }

    /**
     * Tests whether swiping an item once triggers UndoCallback#onUndoShown.
     */
    public void testUndoShown() throws InterruptedException {
        dispatchSwipeMotionEventsAndWait(getInstrumentation(), mAbsListView, 0);

        verify(mUndoCallback).onUndoShown(any(View.class), eq(0));
    }

    /**
     * Tests whether swiping an item twice triggers UndoCallback#onDismiss.
     */
    public void testDismiss() throws InterruptedException {