package Espresso;

import java.util.List;
import classes.Component;
import classes.StepTestCase;
import classes.TestCase;

/**
 * This is the EspressoTranslator class, it takes Action objects and creates Espresso
 * commands that correspond to those Action objects.
 * 
 * @author Nathan Chen
 *
 */
public class EspressoTranslator {
	
	/**
	 * Constructor for the EspressoTranslator class.
	 */
	public EspressoTranslator(){
	}
	
	/**
	 * Iterates through all the StepTestCase objects in the stepTestCases List.
	 * @param testCase The current TestCase object being looked at
	 */
	public void steps_iterator(TestCase testCase){
		String appName = testCase.getAppName();
		String packageName = testCase.getPackageName();
		String mainActivity = testCase.getMainActivity();
		List<StepTestCase> stepTestCases = testCase.getSteps();
		
		for(int i = 0; i < stepTestCases.size(); i++){
			StepTestCase cur = stepTestCases.get(i);
			espresso_switcher(cur.getAction(), cur);
		}
	}
	
	/**
	 * Switching hub for taking different kinds of input, calls methods depending
	 * on what kind of user input is given.
	 * @param action String of the action to be performed
	 * @param s StepTestCase object being looked at 
	 */
	public void espresso_switcher(String action, StepTestCase s){
		
		if(action.equals("CLICK")){
			make_click_command(s.getComponent());
		}
	}

	/**
	 * Generates the click command formatted in the Espresso framework
	 * @param c Component object of the current stepTestCase being analyzed
	 */
	private void make_click_command(Component c) {
		String espresso_command = new String();		
		espresso_command += "onView(withId(R.id." + c.getId().substring(3) + ")).perform(click());";
		System.out.println(espresso_command);
	}
}

@@ -1350,16 +1350,101 @@
 ));%0A%09%09%7D%0A
+%09%09if(action.equals(%22LONG_CLICK%22))%7B%0A%09%09%09make_long_click_command(s.getComponent());%0A%09%09%7D%0A
 %09%7D%0A%0A%09/**
@@ -1820,10 +1820,407 @@
 nd);%0A%09%7D%0A
+%09%0A%09/**%0A%09 * Generates the long click command formatted in the Espresso framework%0A%09 * @param c Component object of the current stepTestCase being analyzed%0A%09 */%0A%09private void make_long_click_command(Component c) %7B%0A%09%09String espresso_command = new String();%09%09%0A%09%09espresso_command += %22onView(withId(R.id.%22 + c.getId().substring(3) + %22)).perform(longClick());%22;%0A%09%09System.out.println(espresso_command);%0A%09%7D%0A
 %7D%0A

Update EspressoTranslator.java