package com.tacitknowledge.slowlight.proxyserver.server.simple;

import com.tacitknowledge.slowlight.proxyserver.config.ServerConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

/**
 * @author Pavel Sorocun (psorocun@tacitknowledge.com)
 */
@RunWith(MockitoJUnitRunner.class)
public class SimpleServerTest
{
    private SimpleServer server;

    @Before
    public void setup()
    {
        server = new SimpleServer(new ServerConfig());
    }

    @Test
    public void shouldCreateInitializer()
    {
        assertThat(server.createChannelInitializer(), is(notNullValue()));
    }
}

@@ -58,16 +58,86 @@
 imple;%0A%0A
+import com.tacitknowledge.slowlight.proxyserver.config.HandlerConfig;%0A
 import c
@@ -193,24 +193,24 @@
 rverConfig;%0A
-
 import org.j
@@ -326,16 +326,71 @@
 unner;%0A%0A
+import java.net.Socket;%0Aimport java.util.Collections;%0A%0A
 import s
@@ -523,16 +523,176 @@
 llValue;
+%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.Assert.fail;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when;
 %0A%0A/**%0A *
@@ -1003,32 +1003,32 @@
 ializer()%0A    %7B%0A
-
         assertTh
@@ -1091,11 +1091,815 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void shouldStartServer() throws Exception%0A    %7B%0A        final Integer localPort = 9090;%0A        final ServerConfig config = mock(ServerConfig.class);%0A%0A        when(config.getLocalPort()).thenReturn(localPort);%0A        when(config.getHandlers()).thenReturn(Collections.%3CHandlerConfig%3EemptyList());%0A%0A        final SimpleServer server = new SimpleServer(config);%0A%0A        server.start();%0A%0A        Socket client = null;%0A        try%0A        %7B%0A            client = new Socket(%22localhost%22, localPort);%0A            assertTrue(client.isConnected());%0A        %7D%0A        catch (Exception ex)%0A        %7B%0A            fail(%22unable to create connection%22);%0A        %7D%0A        finally%0A        %7B%0A            if(client != null)%0A            %7B%0A                client.close();%0A            %7D%0A        %7D%0A    %7D
 %0A%7D%0A

add server start test logic