// Path: src/main/java/com/xebialabs/overcast/command/CommandResponse.java
// public class CommandResponse {
// 
//     private final int returnCode;
// 
//     private final String errors;
// 
//     private final String output;
// 
//     public CommandResponse(int returnCode, String errors, String output) {
//         this.returnCode = returnCode;
//         this.errors = errors;
//         this.output = output;
//     }
// 
//     public int getReturnCode() {
//         return returnCode;
//     }
// 
//     public String getErrors() {
//         return errors;
//     }
// 
//     public String getOutput() {
//         return output;
//     }
// 
//     public boolean isSuccessful() {
//         return getReturnCode() == 0;
//     }
// }
// 
// Path: src/main/java/com/xebialabs/overcast/host/VagrantCloudHost.java
// public class VagrantCloudHost implements CloudHost {
// 
//     protected String vagrantIp;
// 
//     protected String vagrantVm;
// 
//     protected VagrantDriver vagrantDriver;
// 
//     private VagrantState initialState;
// 
//     private Map<String, String> vagrantParameters;
// 
//     private static final Logger logger = LoggerFactory.getLogger(VagrantCloudHost.class);
// 
//     public VagrantCloudHost(String vagrantVm, String vagrantIp, VagrantDriver vagrantDriver,
//                             Map<String, String> vagrantParameters) {
//         this.vagrantIp = vagrantIp;
//         this.vagrantDriver = vagrantDriver;
//         this.vagrantVm = vagrantVm;
//         this.vagrantParameters = vagrantParameters;
//     }
// 
//     @Override
//     public void setup() {
//         initialState = vagrantDriver.state(vagrantVm);
//         logger.info("Vagrant host is in state {}.", initialState.toString());
//         vagrantDriver.doVagrant(vagrantVm, getTransitionCommand(VagrantState.RUNNING, vagrantParameters));
//     }
// 
//     @Override
//     public void teardown() {
//         VagrantState nextState;
//         if (initialState != null) {
//             logger.info("Bringing vagrant back to {} state.", initialState.toString());
//             nextState = initialState;
//         } else {
//             logger.warn("No initial state was captured. Destroying the VM.");
//             nextState = NOT_CREATED;
//         }
//         vagrantDriver.doVagrant(vagrantVm, getTransitionCommand(nextState, vagrantParameters));
//     }
// 
//     @Override
//     public String getHostName() {
//         return vagrantIp;
//     }
// 
//     @Override
//     public int getPort(int port) {
//         return port;
//     }
// 
// }


import com.xebialabs.overcast.command.CommandResponse;
import com.xebialabs.overcast.host.VagrantCloudHost;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static com.xebialabs.overcast.support.vagrant.VagrantState.NOT_CREATED;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;
/**
 *    Copyright 2012-2021 Digital.ai
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.xebialabs.overcast.support.vagrant;



public class VagrantCloudHostTest {

    @Mock
    private VagrantDriver vagrantDriver;

    @BeforeEach
    public void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void shouldThrowNoExceptionsWhenAllGoesFine() {
        when(vagrantDriver.state("vm")).thenReturn(NOT_CREATED);
        when(vagrantDriver.doVagrant("vm", "up")).thenReturn(new CommandResponse(0, "", ""));

        VagrantCloudHost vagrantCloudHost = new VagrantCloudHost("vm", "127.0.0.1", vagrantDriver, null);

        vagrantCloudHost.setup();
    }

    @Test
    public void shouldThrowAnExceptionWhenExitCodeIsNot0() {
        assertThrows(RuntimeException.class, () -> {
// Path: src/main/java/com/xebialabs/overcast/command/CommandResponse.java
// public class CommandResponse {
// 
//     private final int returnCode;
// 
//     private final String errors;
// 
//     private final String output;
// 
//     public CommandResponse(int returnCode, String errors, String output) {
//         this.returnCode = returnCode;
//         this.errors = errors;
//         this.output = output;
//     }
// 
//     public int getReturnCode() {
//         return returnCode;
//     }
// 
//     public String getErrors() {
//         return errors;
//     }
// 
//     public String getOutput() {
//         return output;
//     }
// 
//     public boolean isSuccessful() {
//         return getReturnCode() == 0;
//     }
// }
// 
// Path: src/main/java/com/xebialabs/overcast/host/VagrantCloudHost.java
// public class VagrantCloudHost implements CloudHost {
// 
//     protected String vagrantIp;
// 
//     protected String vagrantVm;
// 
//     protected VagrantDriver vagrantDriver;
// 
//     private VagrantState initialState;
// 
//     private Map<String, String> vagrantParameters;
// 
//     private static final Logger logger = LoggerFactory.getLogger(VagrantCloudHost.class);
// 
//     public VagrantCloudHost(String vagrantVm, String vagrantIp, VagrantDriver vagrantDriver,
//                             Map<String, String> vagrantParameters) {
//         this.vagrantIp = vagrantIp;
//         this.vagrantDriver = vagrantDriver;
//         this.vagrantVm = vagrantVm;
//         this.vagrantParameters = vagrantParameters;
//     }
// 
//     @Override
//     public void setup() {
//         initialState = vagrantDriver.state(vagrantVm);
//         logger.info("Vagrant host is in state {}.", initialState.toString());
//         vagrantDriver.doVagrant(vagrantVm, getTransitionCommand(VagrantState.RUNNING, vagrantParameters));
//     }
// 
//     @Override
//     public void teardown() {
//         VagrantState nextState;
//         if (initialState != null) {
//             logger.info("Bringing vagrant back to {} state.", initialState.toString());
//             nextState = initialState;
//         } else {
//             logger.warn("No initial state was captured. Destroying the VM.");
//             nextState = NOT_CREATED;
//         }
//         vagrantDriver.doVagrant(vagrantVm, getTransitionCommand(nextState, vagrantParameters));
//     }
// 
//     @Override
//     public String getHostName() {
//         return vagrantIp;
//     }
// 
//     @Override
//     public int getPort(int port) {
//         return port;
//     }
// 
// }


// Path: src/test/java/com/xebialabs/overcast/support/vagrant/VagrantCloudHostTest.java
import com.xebialabs.overcast.command.CommandResponse;
import com.xebialabs.overcast.host.VagrantCloudHost;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static com.xebialabs.overcast.support.vagrant.VagrantState.NOT_CREATED;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;

/**
 *    Copyright 2012-2021 Digital.ai
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.xebialabs.overcast.support.vagrant;



public class VagrantCloudHostTest {

    @Mock
    private VagrantDriver vagrantDriver;

    @BeforeEach
    public void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void shouldThrowNoExceptionsWhenAllGoesFine() {
        when(vagrantDriver.state("vm")).thenReturn(NOT_CREATED);
        when(vagrantDriver.doVagrant("vm", "up")).thenReturn(new CommandResponse(0, "", ""));

        VagrantCloudHost vagrantCloudHost = new VagrantCloudHost("vm", "127.0.0.1", vagrantDriver, null);

        vagrantCloudHost.setup();
    }

    @Test
    public void shouldThrowAnExceptionWhenExitCodeIsNot0() {
        assertThrows(RuntimeException.class, () -> {
            when(vagrantDriver.doVagrant("vm", "status")).thenReturn(new CommandResponse(0, "", "not created"));