package uk.co.ribot.easyadapter;

import android.annotation.TargetApi;
import android.os.Build;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import junit.framework.Assert;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import uk.co.ribot.easyadapter.annotations.FieldAnnotationParser;
import uk.co.ribot.easyadapter.annotations.ViewId;

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) //Disable because this code will run inside robolectric with api level 17+
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class FieldAnnotationParserTest {

    private static final int TEXT_VIEW_ID = 1000;
    private static final int IMAGE_VIEW_ID = 2000;

    @Test public void testSetViewFields() throws Exception {
        TestObjectWithAnnotations testObject = new TestObjectWithAnnotations();
        FieldAnnotationParser.setViewFields(testObject, createTestLinearLayout());
        Assert.assertNotNull(testObject.textView);
        Assert.assertNotNull(testObject.imageView);
    }

/*    @Test public void testSetViewFieldsActivity() throws Exception {

    }*/

    @SuppressWarnings("ResourceType") //Because of warning when setting a hardcoded ID into the view
    private LinearLayout createTestLinearLayout() {
        LinearLayout linearLayout = new LinearLayout(Robolectric.application);
        TextView textView = new TextView(Robolectric.application);
        textView.setId(TEXT_VIEW_ID);
        linearLayout.addView(textView);
        ImageView imageView = new ImageView(Robolectric.application);
        imageView.setId(IMAGE_VIEW_ID);
        linearLayout.addView(imageView);
        return linearLayout;
    }

    private class TestObjectWithAnnotations {

        @ViewId(TEXT_VIEW_ID)
        TextView textView;
        @ViewId(IMAGE_VIEW_ID)
        ImageView imageView;

    }
}

@@ -83,16 +83,71 @@
 oid.
-os.Build
+app.Activity;%0Aimport android.os.Build;%0Aimport android.os.Bundle
 ;%0Aim
@@ -1251,10 +1251,8 @@
  %7D%0A%0A
-/*
     
@@ -1320,16 +1320,362 @@
 n %7B%0A
+        Activity testActivity = Robolectric.buildActivity(TestActivity.class).create().get();%0A        TestObjectWithAnnotations testObject = new TestObjectWithAnnotations();;%0A        FieldAnnotationParser.setViewFields(testObject, testActivity);%0A        Assert.assertNotNull(testObject.textView);%0A        Assert.assertNotNull(testObject.imageView);
 %0A    %7D
-*/
 %0A%0A  
@@ -1785,16 +1785,23 @@
 private 
+static 
 LinearLa
@@ -2413,11 +2413,258 @@
 ;%0A%0A    %7D
+%0A%0A    static class TestActivity extends Activity %7B%0A        @Override%0A        protected void onCreate(Bundle savedInstanceState) %7B%0A            super.onCreate(savedInstanceState);%0A            setContentView(createTestLinearLayout());%0A        %7D%0A    %7D
 %0A%7D%0A

Add test testSetViewFieldsActivity