package net.sourcewalker.android.calculon;

import android.test.ActivityInstrumentationTestCase2;

import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;

public class CalculatorActivityTest extends ActivityInstrumentationTestCase2<CalculatorActivity> {

    public CalculatorActivityTest() {
        super(CalculatorActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        getActivity();
    }

    public void testStartUp() throws Exception {
        onView(withId(R.id.input)).check(matches(withText("0")));
    }

    public void testPressNumber() throws Exception {
        onView(withId(R.id.number_5)).perform(click());
        onView(withId(R.id.input)).check(matches(withText("5")));
    }

    public void testLongNumber() throws Exception {
        onView(withId(R.id.number_4)).perform(click());
        onView(withId(R.id.number_2)).perform(click());
        onView(withId(R.id.input)).check(matches(withText("42")));
    }

    public void testClear() throws Exception {
        onView(withId(R.id.input)).check(matches(withText("0")));
        onView(withText("9")).perform(click());
        onView(withId(R.id.input)).check(matches(withText("9")));
        onView(withId(R.id.clear)).perform(click());
        onView(withId(R.id.input)).check(matches(withText("0")));
    }

}
@@ -915,64 +915,23 @@
     
-onView(withId(R.id.input)).check(matches(withTex
+checkInpu
 t(%220%22)
-))
 ;%0A  
@@ -992,37 +992,35 @@
 n %7B%0A        
-onView(withId
+pressButton
 (R.id.number
@@ -1026,92 +1026,33 @@
 r_5)
-).perform(click());%0A        onView(withId(R.id.input)).check(matches(withTex
+;%0A        checkInpu
 t(%225%22)
-))
 ;%0A  
@@ -1112,37 +1112,35 @@
 n %7B%0A        
-onView(withId
+pressButton
 (R.id.number
@@ -1146,149 +1146,70 @@
 r_4)
-).perform(click());%0A        onView(withId(R.id.number_2)).perform(click());%0A        onView(withId(R.id.input)).check(matches(withTex
+;%0A        pressButton(R.id.number_2);%0A        checkInpu
 t(%2242%22)
-))
 ;%0A  
@@ -1272,64 +1272,23 @@
     
-onView(withId(R.id.input)).check(matches(withTex
+checkInpu
 t(%220%22)
-))
 ;%0A  
@@ -1325,32 +1325,166 @@
 rform(click());%0A
+        checkInput(%229%22);%0A        pressButton(R.id.clear);%0A        checkInput(%220%22);%0A    %7D%0A%0A    private void checkInput(String value) %7B%0A
         onView(w
@@ -1525,19 +1525,21 @@
 ithText(
-%229%22
+value
 )));%0A   
@@ -1543,119 +1543,91 @@
     
+%7D%0A%0A
     
-onView(withId(R.id.clear)).perform(click());%0A        onView(withId(R.id.input)).check(matches(withText(%220%22)
+private void pressButton(int id) %7B%0A        onView(withId(id)).perform(click(
 ));%0A

Test refactor.