package info.javaspec.console;

import de.bechte.junit.runners.context.HierarchicalContextRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;

@RunWith(HierarchicalContextRunner.class)
public class MainTest {
  public class runCommand {
    private Main subject;
    private Reporter reporter;
    private Main.ExitHandler system;
    private Command command;

    @Before
    public void setup() {
      this.reporter = Mockito.mock(Reporter.class);
      this.system = Mockito.mock(Main.ExitHandler.class);
      this.subject = new Main(this.reporter, this.system);
      this.command = Mockito.mock(Command.class);
    }

    @Test
    public void runsTheCommand() throws Exception {
      Mockito.stub(this.command.run()).toReturn(Result.success());
      subject.runCommand(this.command);
      Mockito.verify(this.command, Mockito.times(1)).run();
    }

    @Test
    public void exitsWithTheExitCodeReturnedByTheCommand() throws Exception {
      Result failure = Result.failure(42, "...you're not going to like it.");
      Mockito.stub(this.command.run()).toReturn(failure);
      subject.runCommand(this.command);
      Mockito.verify(this.system, Mockito.times(1)).exit(42);
    }

    @Test
    public void reportsTheResult() throws Exception {
      Result result = Mockito.mock(Result.class);
      Mockito.stub(this.command.run()).toReturn(result);
      subject.runCommand(this.command);
      Mockito.verify(result).reportTo(Mockito.same(this.reporter));
    }
  }
}

@@ -597,21 +597,16 @@
 ew Main(
-this.
 reporter
@@ -607,21 +607,16 @@
 porter, 
-this.
 system);
@@ -746,37 +746,32 @@
    Mockito.stub(
-this.
 command.run()).t
@@ -814,37 +814,32 @@
 ject.runCommand(
-this.
 command);%0A      
@@ -853,21 +853,16 @@
 .verify(
-this.
 command,
@@ -1071,37 +1071,32 @@
    Mockito.stub(
-this.
 command.run()).t
@@ -1130,37 +1130,32 @@
 ject.runCommand(
-this.
 command);%0A      
@@ -1169,21 +1169,16 @@
 .verify(
-this.
 system, 
@@ -1345,21 +1345,16 @@
 to.stub(
-this.
 command.
@@ -1403,21 +1403,16 @@
 Command(
-this.
 command)
@@ -1464,21 +1464,16 @@
 to.same(
-this.
 reporter

Remove unnecessary this