package com.collective.celos.ui;

import junit.framework.Assert;
import org.apache.commons.cli.*;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;

public class UICommandLineParserTest {

    @Test
    public void testParsesOk() throws Exception {
        UICommandLineParser parser = new UICommandLineParser();
        String[] clParams = ("--celosAddr http://localhost:8888 --port 1234").split(" ");

        UICommandLine commandLine = parser.parse(clParams);
        Assert.assertEquals(commandLine.getCelosUrl(), new URL("http://localhost:8888"));
        Assert.assertEquals(commandLine.getPort(), 1234);

    }
    
    @Test(expected = IllegalArgumentException.class)
    public void testPortMissing() throws Exception {
        UICommandLineParser parser = new UICommandLineParser();
        String[] clParams = ("--celosAddr localhost:8888").split(" ");

        parser.parse(clParams);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testCelosURLMissing() throws Exception {
        UICommandLineParser parser = new UICommandLineParser();
        String[] clParams = ("--port 8888").split(" ");

        parser.parse(clParams);
    }

    @Test(expected = MalformedURLException.class)
    public void testWrongAddress() throws Exception {
        UICommandLineParser parser = new UICommandLineParser();
        String[] clParams = ("--celosAddr localhost:8888 --port 1234").split(" ");

        parser.parse(clParams);
    }

    @Test(expected = NumberFormatException.class)
    public void testWrongPort() throws Exception {
        UICommandLineParser parser = new UICommandLineParser();
        String[] clParams = ("--celosAddr http://localhost:8888 --port abc").split(" ");

        parser.parse(clParams);
    }

}

@@ -595,36 +595,32 @@
 rams = (%22--celos
-Addr
  http://localhos
@@ -644,32 +644,32 @@
 4%22).split(%22 %22);%0A
+
 %0A        UIComma
@@ -1072,36 +1072,32 @@
 rams = (%22--celos
-Addr
  localhost:8888%22
@@ -1625,20 +1625,16 @@
 %22--celos
-Addr
  localho
@@ -1864,32 +1864,32 @@
 ndLineParser();%0A
+
         String%5B%5D
@@ -1909,20 +1909,16 @@
 %22--celos
-Addr
  http://

fix test