/*
 * Copyright 2016 Palantir Technologies, Inc. All rights reserved.
 *
 * THIS SOFTWARE CONTAINS PROPRIETARY AND CONFIDENTIAL INFORMATION OWNED BY PALANTIR TECHNOLOGIES INC.
 * UNAUTHORIZED DISCLOSURE TO ANY THIRD PARTY IS STRICTLY PROHIBITED
 *
 * For good and valuable consideration, the receipt and adequacy of which is acknowledged by Palantir and recipient
 * of this file ("Recipient"), the parties agree as follows:
 *
 * This file is being provided subject to the non-disclosure terms by and between Palantir and the Recipient.
 *
 * Palantir solely shall own and hereby retains all rights, title and interest in and to this software (including,
 * without limitation, all patent, copyright, trademark, trade secret and other intellectual property rights) and
 * all copies, modifications and derivative works thereof.  Recipient shall and hereby does irrevocably transfer and
 * assign to Palantir all right, title and interest it may have in the foregoing to Palantir and Palantir hereby
 * accepts such transfer. In using this software, Recipient acknowledges that no ownership rights are being conveyed
 * to Recipient.  This software shall only be used in conjunction with properly licensed Palantir products or
 * services.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.palantir.docker.compose.execution;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.mockito.Matchers.anyVararg;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class SynchronousDockerComposeExecutableShould {
    @Mock private Process executedProcess;
    @Mock private DockerComposeExecutable dockerComposeExecutable;
    private SynchronousDockerComposeExecutable dockerCompose;

    @Before
    public void setup() throws IOException {
        when(dockerComposeExecutable.execute(anyVararg())).thenReturn(executedProcess);
        dockerCompose = new SynchronousDockerComposeExecutable(dockerComposeExecutable);

        givenTheProcessHasOutput("");
        givenTheProcessTerminatesWithAnExitCodeOf(0);
    }

    @Test public void
    respond_with_the_exit_code_of_the_executed_process() throws IOException {
        givenTheProcessTerminatesWithAnExitCodeOf(1);

        assertThat(dockerCompose.run("rm", "-f").exitCode(), is(1));
    }

    @Test public void
    respond_with_the_output_of_the_executed_process() throws IOException {
        givenTheProcessHasOutput("some output");

        assertThat(dockerCompose.run("rm", "-f").output(), is("some output"));
    }

    private void givenTheProcessHasOutput(String output) {
        byte[] outputBytes = output.getBytes(StandardCharsets.UTF_8);
        when(executedProcess.getInputStream())
                .thenReturn(new ByteArrayInputStream(outputBytes));
    }

    private void givenTheProcessTerminatesWithAnExitCodeOf(int exitCode) {
        when(executedProcess.exitValue()).thenReturn(exitCode);
    }

}

@@ -3012,32 +3012,42 @@
         givenThe
+Underlying
 ProcessHasOutput
@@ -3060,32 +3060,42 @@
         givenThe
+Underlying
 ProcessTerminate
@@ -3227,32 +3227,85 @@
 n %7B%0A        
-givenThe
+int expectedExitCode = 1;%0A        %0A        givenTheUnderlying
 ProcessTermi
@@ -3326,17 +3326,32 @@
 tCodeOf(
-1
+expectedExitCode
 );%0A%0A    
@@ -3410,17 +3410,32 @@
 e(), is(
-1
+expectedExitCode
 ));%0A    
@@ -3542,24 +3542,82 @@
         
-givenThe
+String expectedOutput = %22some output%22;%0A%0A        givenTheUnderlying
 ProcessH
@@ -3625,29 +3625,30 @@
 sOutput(
-%22some o
+expectedO
 utput
-%22
 );%0A%0A    
@@ -3705,29 +3705,30 @@
 t(), is(
-%22some o
+expectedO
 utput
-%22
 ));%0A    
@@ -3751,24 +3751,34 @@
 oid givenThe
+Underlying
 ProcessHasOu
@@ -4016,16 +4016,26 @@
 givenThe
+Underlying
 ProcessT

Remove duplication of value