package com.leandog.gametel.driver.commands;

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

import org.junit.*;
import org.mockito.*;

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

public class CommandRunnerTest {

    @Mock Solo solo;
    CommandRunner commandRunner;

    @Before
    public void setUp() {
        initMocks();
        commandRunner = new CommandRunner();
    }

    @Test
    public void itCanInvokeParameterless() throws Exception {
        commandRunner.execute(new Command("goBack"));
        verify(solo).goBack();
    }

    @Test
    public void itCanGiveTheLastResult() throws Exception {
        when(solo.scrollDown()).thenReturn(true);
        commandRunner.execute(new Command("scrollDown"));
        assertThat(commandRunner.theLastResult(), equalTo((Object) true));
    }

    @Test
    public void itCanInvokeMethodsTakingIntegers() throws Exception {
        commandRunner.execute(new Command("clearEditText", 3));
        verify(solo).clearEditText(3);
    }

    @Test
    public void itCanInvokeMethodsTakingFloats() throws Exception {
        commandRunner.execute(new Command("clickLongOnScreen", 1.0f, 2.0f));
        verify(solo).clickLongOnScreen(1.0f, 2.0f);
    }

    @Test
    public void itCanInvokeMethodsTakingAString() throws Exception {
        commandRunner.execute(new Command("clickLongOnText", "someText"));
        verify(solo).clickLongOnText("someText");
    }
    
    @Test
    public void itCanChainMethodCallsFromTheLastResult() throws Exception {
        commandRunner.execute(new Command("getClass"), new Command("getName"));
        assertThat(commandRunner.theLastResult(), equalTo((Object)solo.getClass().getName()));
    }

    @Test
    public void itCanInvokeMethodsTakingABoolean() throws Exception {
        commandRunner.execute(new Command("clickOnText", "someText", 123, true));
        verify(solo).clickOnText("someText", 123, true);
    }
    
    @Test
    public void itClearsTheLastResultBeforeExecutingAgain() throws Exception {
        commandRunner.execute(new Command("scrollDown"));
        commandRunner.execute(new Command("scrollDown"));
        verify(solo, times(2)).getClass();
    }

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

@@ -2182,35 +2182,39 @@
 ew Command(%22
-scrollDown%22
+clickInList%22, 0
 ));%0A        
@@ -2244,35 +2244,39 @@
 ew Command(%22
-scrollDown%22
+clickInList%22, 0
 ));%0A        
@@ -2298,25 +2298,29 @@
 mes(2)).
-getClass(
+clickInList(0
 );%0A    %7D

fix test