package victory.sandbox.mytestapp;

import android.os.Looper;
import android.test.mock.MockContext;
import android.view.MotionEvent;
import android.view.ViewStub;

import junit.framework.TestCase;

public class SwipeDetectorTest extends TestCase {

    private ViewStub mockView;
    private int x;
    private int y;
    MotionEvent event;
    SwipeDetector swipeDetector;

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

        class MyMockContect extends MockContext {
            public Looper getMainLooper() {
                return Looper.getMainLooper();
            }
        }
        MyMockContect context = new MyMockContect();
        x = 0; y = 0;
        mockView = new ViewStub(context);
        swipeDetector = new SwipeDetector();
    }

    public void tearDown() throws Exception {

    }

    public void testOnTouch() throws Exception {
        x = 0; y = 0;
        event = MotionEvent.obtain(1, 0, MotionEvent.ACTION_DOWN, x, y, 0);
        assertFalse(swipeDetector.onTouch(mockView, event));

        x = 30;
        y = 0;
        event = MotionEvent.obtain(1, 1, MotionEvent.ACTION_MOVE, x, y, 0);

        boolean isAction = swipeDetector.onTouch(mockView, event);
        assertTrue(isAction);

        boolean result =
                swipeDetector.getSwipeHorizontal().equals(SwipeDetector.Action.LeftToRight);
        assertTrue(result);

        // check we don't have a stray vertical action
        result = swipeDetector.getSwipeVertical().equals(SwipeDetector.Action.None);
        assertTrue(result);

        // start a new event
        x = 0; y = 0;
        event = MotionEvent.obtain(1, 0, MotionEvent.ACTION_DOWN, x, y, 0);
        swipeDetector.onTouch(mockView, event);
        x = 0; y = 30;
        event = MotionEvent.obtain(1, 0, MotionEvent.ACTION_MOVE, x, y, 0);
        isAction = swipeDetector.onTouch(mockView, event);
        assertTrue(isAction);
        result = swipeDetector.getSwipeVertical().equals(SwipeDetector.Action.UpToDown);
        assertTrue(result);
    }

    public void testGetSetMinMotion() throws Exception {
        swipeDetector.setMinMotion(30);
        assertTrue(swipeDetector.getMinMotion() == 30);
    }
}
@@ -460,17 +460,17 @@
 ockConte
-c
+x
 t extend
@@ -619,17 +619,17 @@
 ockConte
-c
+x
 t contex
@@ -647,17 +647,17 @@
 ockConte
-c
+x
 t();%0A   

fix spelling