package commands;

import static commands.CommandParameterBuilder.aCommand;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static timeline.builder.WallOutputBuilder.aWallOutput;

import org.junit.Test;

import timeline.Output;
import application.CommandObserver;

public class ObservableCommandTest {
    private static final CommandParameter PARAMETER = aCommand().create();
    private static final Output OUTPUT = aWallOutput().create();

    @Test
    public void givenCreatedWithACommandWhenItIsExecutedThenItCallsTheGivenCommand() {
        Command command = mock(Command.class);
        when(command.executeCommand(PARAMETER)).thenReturn(OUTPUT);
        ObservableCommand observableCommand = new ObservableCommand(command);
        CommandObserver observer = mock(CommandObserver.class);
        observableCommand.registerObserver(observer);

        observableCommand.executeCommand(PARAMETER);

        verify(command).executeCommand(PARAMETER);
    }

    @Test
    public void givenRegisteredObserversWhenItIsExecutedThenItNotifiesTheObserverWithTheOutput() {
        Command command = mock(Command.class);
        when(command.executeCommand(PARAMETER)).thenReturn(OUTPUT);
        ObservableCommand observableCommand = new ObservableCommand(command);
        CommandObserver observer = mock(CommandObserver.class);
        observableCommand.registerObserver(observer);

        observableCommand.executeCommand(PARAMETER);

        verify(observer).update(OUTPUT);
    }
}

@@ -250,24 +250,49 @@
 allOutput;%0A%0A
+import org.junit.Before;%0A
 import org.j
@@ -550,223 +550,66 @@
     
-@Test%0A    public void givenCreatedWithACommandWhenItIsExecutedThenItCallsTheGivenCommand() %7B%0A        Command command = mock(Command.class);%0A        when(command.executeCommand(PARAMETER)).thenReturn(OUTPUT);%0A       
+private Command command = mock(Command.class);%0A    private
  Obs
@@ -671,35 +671,39 @@
 d(command);%0A    
-   
+private
  CommandObserver
@@ -747,165 +747,166 @@
 s);%0A
+%0A
     
-    observableCommand.registerObserver(observer);%0A%0A        observableCommand.executeCommand(PARAMETER);%0A%0A        verify(command).executeCommand(PARAMETER
+@Before%0A    public void setUp() %7B%0A        when(command.executeCommand(PARAMETER)).thenReturn(OUTPUT);%0A        observableCommand.registerObserver(observer
 );%0A 
@@ -946,27 +946,27 @@
 iven
-RegisteredObservers
+CreatedWithACommand
 When
@@ -987,100 +987,95 @@
 enIt
-NotifiesTheObserverWithTheOutput() %7B%0A        Command command = mock(Command.class
+CallsTheGivenCommand() %7B%0A        observableCommand.executeCommand(PARAMETER
 );%0A
+%0A
         
 when
@@ -1066,36 +1066,38 @@
 );%0A%0A        
-when
+verify
 (command
 .executeComm
@@ -1076,32 +1076,33 @@
   verify(command
+)
 .executeCommand(
@@ -1115,226 +1115,125 @@
 TER)
-).thenReturn(OUTPUT)
 ;%0A    
+%7D%0A%0A
     
-ObservableCommand observableCommand = new ObservableCommand(command);%0A        CommandObserver observer = mock(CommandObserver.class);%0A        observableCommand.registerObserver(observer);%0A
+@Test%0A    public void givenRegisteredObserversWhenItIsExecutedThenItNotifiesTheObserverWithTheOutput() %7B
 %0A   

removed duplication