package fr.tvbarthel.apps.shapi;

import android.app.Instrumentation;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.squareup.spoon.Spoon;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import fr.tvbarthel.apps.shapi.engine.DropZone;
import fr.tvbarthel.apps.shapi.game.DropZoneView;
import fr.tvbarthel.apps.shapi.shape.Circle;
import fr.tvbarthel.apps.shapi.shape.Diamond;
import fr.tvbarthel.apps.shapi.shape.Rectangle;
import fr.tvbarthel.apps.shapi.shape.TestActivity;
import fr.tvbarthel.apps.shapi.shape.Triangle;

/**
 * Android test for the class {@link DropZoneView}
 */
@RunWith(AndroidJUnit4.class)
public class DropZoneViewAndroidTest {

    @Rule
    public ActivityTestRule<TestActivity> activityRule = new ActivityTestRule<>(TestActivity.class);
    private Instrumentation instrumentation;
    private DropZoneView dropZoneView;

    @Before
    public void setup() {
        instrumentation = InstrumentationRegistry.getInstrumentation();
        setContentView();
        final TestActivity activity = activityRule.getActivity();
        dropZoneView = ((DropZoneView) activity.findViewById(R.id.test_drop_zone_box_view));
    }

    @Test
    public void dropZoneForRectangle() {
        final DropZone dropZone = new DropZone(Rectangle.class);
        final TestActivity activity = activityRule.getActivity();
        setDropZone(dropZone);
        Spoon.screenshot(activity, "drop-zone-for-rectangle");
    }

    @Test
    public void dropZoneForTriangle() {
        final DropZone dropZone = new DropZone(Triangle.class);
        final TestActivity activity = activityRule.getActivity();
        setDropZone(dropZone);
        Spoon.screenshot(activity, "drop-zone-for-triangle");
    }

    @Test
    public void dropZoneForCircle() {
        final DropZone dropZone = new DropZone(Circle.class);
        final TestActivity activity = activityRule.getActivity();
        setDropZone(dropZone);
        Spoon.screenshot(activity, "drop-zone-for-circle");
    }

    @Test
    public void dropZoneForDiamond() {
        final DropZone dropZone = new DropZone(Diamond.class);
        final TestActivity activity = activityRule.getActivity();
        setDropZone(dropZone);
        Spoon.screenshot(activity, "drop-zone-for-diamond");
    }

    private void setContentView() {
        instrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                activityRule.getActivity().setContentView(R.layout.test_shape_box_view);
            }
        });
    }

    private void setDropZone(final DropZone dropZone) {
        instrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                dropZoneView.setDropZone(dropZone);
            }
        });
    }
}

@@ -357,16 +357,47 @@
 nWith;%0A%0A
+import java.util.Collections;%0A%0A
 import f
@@ -423,13 +423,11 @@
 api.
-engin
+gam
 e.Dr
@@ -619,24 +619,68 @@
 .Rectangle;%0A
+import fr.tvbarthel.apps.shapi.shape.Shape;%0A
 import fr.tv
@@ -1498,32 +1498,81 @@
 (Rectangle.class
+, Collections.%3CClass%3C? extends Shape%3E%3EemptyList()
 );%0A        final
@@ -1828,32 +1828,81 @@
 e(Triangle.class
+, Collections.%3CClass%3C? extends Shape%3E%3EemptyList()
 );%0A        final
@@ -2157,24 +2157,73 @@
 Circle.class
+, Collections.%3CClass%3C? extends Shape%3E%3EemptyList()
 );%0A        f
@@ -2422,24 +2422,24 @@
 Diamond() %7B%0A
-
         fina
@@ -2482,24 +2482,73 @@
 iamond.class
+, Collections.%3CClass%3C? extends Shape%3E%3EemptyList()
 );%0A        f

Fix drop zone view android tests