package fi.helsinki.cs.tmc.cli.command;

import static org.junit.Assert.assertTrue;

import fi.helsinki.cs.tmc.cli.Application;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;

public class LoginCommandTest {

    private static String serverAddress;
    private static String username;
    private static String password;

    private Application app;
    private OutputStream os;

    public LoginCommandTest() {
    }

    @BeforeClass
    public static void setUpClass() {
        LoginCommandTest.serverAddress = System.getenv("TMC_SERVER_ADDRESS");
        LoginCommandTest.username = System.getenv("TMC_USERNAME");
        LoginCommandTest.password = System.getenv("TMC_PASSWORD");
    }

    @Before
    public void setUp() {
        this.app = new Application();
        this.os = new ByteArrayOutputStream();

        PrintStream ps = new PrintStream(os);
        System.setOut(ps);
    }

    @Test
    public void logsInWithCorrectServerUserAndPassword() {
        String[] args = {"login",
            "-s", LoginCommandTest.serverAddress,
            "-u", LoginCommandTest.username,
            "-p", LoginCommandTest.password};

        app.run(args);
        String output = os.toString();
        assertTrue(output.contains("Login successful!"));
    }
}

@@ -1117,17 +1117,19 @@
 s = 
-%7B%22login%22,
+createArgs(
 %0A   
@@ -1141,13 +1141,11 @@
     
-%22-s%22,
+   
  Log
@@ -1189,13 +1189,11 @@
     
-%22-u%22,
+   
  Log
@@ -1232,13 +1232,11 @@
     
-%22-p%22,
+   
  Log
@@ -1257,17 +1257,17 @@
 password
-%7D
+)
 ;%0A%0A     
@@ -1386,11 +1386,446 @@
 );%0A    %7D
+%0A%0A    private String%5B%5D createArgs(String server, String username, String pwd) %7B%0A        return new String%5B%5D%7B%0A            %22login%22,%0A            %22-s%22, server,%0A            %22-u%22, username,%0A            %22-p%22, pwd%7D;%0A    %7D%0A%0A    private String%5B%5D createArgs(String username, String pwd) %7B%0A        return new String%5B%5D%7B%0A            %22login%22,%0A            %22-s%22, LoginCommandTest.serverAddress,%0A            %22-u%22, username,%0A            %22-p%22, pwd%7D;%0A    %7D
 %0A%7D%0A

Add helper methods for creating args