package com.leandog.gametel.driver.commands;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import com.jayway.android.robotium.solo.Solo;
import com.leandog.gametel.driver.TestRunInformation;

public class CommandRunnerTest {
    
    @Mock Solo solo;
    
    private CommandRunner commandRunner;
    
    @Before
    public void setUp() {
        initMocks();
        commandRunner = new CommandRunner();
    }
    
    @Test
    public void itCanInvokeParameterlessSoloMethod() {
        commandRunner.execute(new Command("goBack"));
        verify(solo).goBack();
    }
    
    @Test
    public void itCanGiveTheLastResult() {
        when(solo.scrollDown()).thenReturn(true);
        commandRunner.execute(new Command("scrollDown"));
        assertThat(commandRunner.theLastResult(), equalTo((Object)true));
    }
    
    @Test
    public void itCanCallSoloMethodsThatTakeIntegers() {
        commandRunner.execute(new Command("clearEditText", 3));
        verify(solo).clearEditText(3);
    }

    private void initMocks() {
        MockitoAnnotations.initMocks(this);
        TestRunInformation.setSolo(solo);
    }
}

@@ -262,16 +262,97 @@
 t.Test;%0A
+import org.junit.experimental.runners.Enclosed;%0Aimport org.junit.runner.RunWith;%0A
 import o
@@ -509,16 +509,41 @@
 ation;%0A%0A
+@RunWith(Enclosed.class)%0A
 public c
@@ -571,22 +571,81 @@
 t %7B%0A
+%0A
     
-%0A
+public static class ExecutingAgainstRobotium %7B%0A   
     
+ 
 @Mock
+%0A       
  Sol
@@ -652,25 +652,24 @@
 o solo;%0A    
-%0A
     private 
@@ -697,21 +697,21 @@
 Runner;%0A
+%0A
     
-%0A
     @Bef
@@ -714,16 +714,20 @@
 @Before%0A
+    
     publ
@@ -740,24 +740,28 @@
 d setUp() %7B%0A
+    
         init
@@ -769,32 +769,36 @@
 ocks();%0A        
+    
 commandRunner = 
@@ -814,39 +814,43 @@
 ndRunner();%0A    
-%7D
+    %7D%0A
 %0A    
-%0A
     @Test%0A    pu
@@ -835,32 +835,36 @@
 %0A%0A        @Test%0A
+    
     public void 
@@ -902,32 +902,36 @@
 hod() %7B%0A        
+    
 commandRunner.ex
@@ -960,32 +960,36 @@
 ack%22));%0A        
+  
+  
 verify(solo).goB
@@ -995,27 +995,31 @@
 Back();%0A
+    
     %7D%0A
+%0A
     
-%0A
     @Tes
@@ -1016,32 +1016,36 @@
       @Test%0A    
+  
+  
 public void itCa
@@ -1063,24 +1063,28 @@
 tResult() %7B%0A
+    
         when
@@ -1121,16 +1121,20 @@
 (true);%0A
+    
         
@@ -1191,16 +1191,20 @@
         
+    
 assertTh
@@ -1253,16 +1253,17 @@
 (Object)
+ 
 true));%0A
@@ -1270,15 +1270,19 @@
     
-%7D
+    %7D%0A
 %0A    
-%0A
     
@@ -1283,24 +1283,28 @@
       @Test%0A
+    
     public v
@@ -1348,32 +1348,36 @@
 ers() %7B%0A        
+    
 commandRunner.ex
@@ -1416,32 +1416,36 @@
 %22, 3));%0A        
+ 
+   
 verify(solo).cle
@@ -1463,23 +1463,31 @@
 3);%0A    
-%7D%0A%0A
+    %7D%0A%0A   
     
+ 
 private 
@@ -1501,24 +1501,28 @@
 itMocks() %7B%0A
+    
         Mock
@@ -1561,16 +1561,20 @@
         
+    
 TestRunI
@@ -1599,16 +1599,26 @@
 (solo);%0A
+        %7D%0A
     %7D%0A%7D%0A

use Enclosed.class test runner for CommandRunnerTest