package com.lyrch.openbrew.test;

import com.lyrch.openbrew.IngredientActivity;
import com.lyrch.openbrew.RecipeActivity;

import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;

public class IngredientActivityTest extends ActivityInstrumentationTestCase2<IngredientActivity> {

	public static final int INGREDIENT_TYPE_COUNT = 8;
	
	private IngredientActivity mActivity;
	private Spinner mSpinner;
	private SpinnerAdapter mIngredientTypes;
	
	public IngredientActivityTest() {
		super(IngredientActivity.class);
	}
	
	protected void setUp() throws Exception {
		super.setUp();
		setActivityInitialTouchMode(false);
        System.out.println("Setting up.");
	    mActivity = getActivity();
	    
	    mSpinner = (Spinner) mActivity.findViewById(com.lyrch.openbrew.R.id.ingredient_type_spinner);
	    mIngredientTypes = mSpinner.getAdapter();
	}
	
	public void testPreConditions() {
		System.out.println(mSpinner.toString());
		assertTrue(mSpinner.getOnItemSelectedListener() != null);
		assertTrue(mIngredientTypes != null);
		assertEquals(mIngredientTypes.getCount(), INGREDIENT_TYPE_COUNT);
	}
}

@@ -147,16 +147,54 @@
 Intent;%0A
+import android.content.res.Resources;%0A
 import a
@@ -239,16 +239,46 @@
 tCase2;%0A
+import android.view.KeyEvent;%0A
 import a
@@ -491,16 +491,107 @@
 NT = 8;%0A
+%09public static final int TEST_POSITION = 3;%0A%09public static final int INITIAL_POSITION = 0;%0A
 %09%0A%09priva
@@ -692,16 +692,63 @@
 tTypes;%0A
+%09private String mSelection;%0A%09private int mPos;%0A
 %09%0A%09publi
@@ -1316,32 +1316,32 @@
 Types != null);%0A
-
 %09%09assertEquals(m
@@ -1394,11 +1394,732 @@
 UNT);%0A%09%7D
+%0A%0A%09public void testIngredientSelectionUI() %7B%0A%09%09mActivity.runOnUiThread(%0A%09%09  new Runnable() %7B%0A%09%09%09public void run() %7B%0A%09%09%09  mSpinner.requestFocus();%0A%09%09%09  mSpinner.setSelection(INITIAL_POSITION);%0A%09%09%09%7D%0A%09%09  %7D%0A%09%09);%0A%0A%09%09this.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);%0A%09    for (int i = 1; i %3C= TEST_POSITION; i++) %7B%0A%09      this.sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);%0A%09    %7D%0A%09    this.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);%0A%0A%09    mPos = mSpinner.getSelectedItemPosition();%0A%09    mSelection = (String)mSpinner.getItemAtPosition(mPos);%0A%0A%09    Resources res = mActivity.getResources();%0A%09    String%5B%5D ingredients = res.getStringArray(com.lyrch.openbrew.R.array.ingredient_types);%0A%09    assertEquals(ingredients%5BTEST_POSITION%5D,mSelection);%0A%09%7D
 %0A%7D%0A

Add test for selecting an ingredient type.