package ru.matevosyan.client;

import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.Socket;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
 * Created by Admin on 26.03.2017.
 */
public class BotClientTest {

    private static final String LN = System.getProperty("line.separator");

    public void whenClientSendThenServerReturn(String input, String expected, String typeIn) throws IOException {
        Socket socket = mock(Socket.class);

//        ByteArrayOutputStream outType = new ByteArrayOutputStream();
//        System.setOut(new PrintStream(outType));

        ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes());
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        ByteArrayInputStream typeValue = new ByteArrayInputStream(typeIn.getBytes());
        System.setIn(typeValue);

        when(socket.getInputStream()).thenReturn(in);
        when(socket.getOutputStream()).thenReturn(out);

        BotClient botClient = new BotClient(socket);
        botClient.startClient();

        assertThat(socket.getOutputStream(), is(expected));
    }


//    @Test
//    public void whenSendHelloThenReturnHello() throws IOException {
//        this.whenClientSendThenServerReturn("Hello my friend",
//                String.format("Type something to send to Oracle%sSending this line to the server...%s" +
//                                "Server ~ Hello my friend%sSending this line to the server...%sServer ~ null%s",
//                        LN, LN, LN, LN, LN),
//                String.format("Hello%sBye", LN));
//    }
    @Test
    public void whenSendByThenReturnEmpty() throws IOException {
        this.whenClientSendThenServerReturn("Hello my friend", "Hello my friend", String.format("Hello%sBye", LN));
    }

    @Test
    public void whenSendHelloThenReturnHello() throws IOException {

    }
}
@@ -495,24 +495,25 @@
 parator%22);%0A%0A
+%0A
     public v
@@ -1244,24 +1244,26 @@
 ent();%0A%0A
+//
         
 assertTh
@@ -1258,41 +1258,286 @@
     
-assertThat(socket.getOutputStream
+byte%5B%5D buff = new byte%5B1024%5D;%0A//        int len;%0A//%0A//        OutputStream outputStream = new ByteArrayOutputStream();%0A//        while ((len = socket.getInputStream().read(buff)) %3E 0) %7B%0A//            outputStream.write(buff, 0, len);%0A//        %7D%0A%0A        assertThat(out.toString
 (), 
@@ -1559,18 +1559,16 @@
     %7D%0A%0A%0A
-//
     @Tes
@@ -1569,18 +1569,16 @@
   @Test%0A
-//
     publ
@@ -1585,37 +1585,35 @@
 ic void whenSend
-Hello
+Bye
 ThenReturnHello(
@@ -1598,37 +1598,37 @@
 endByeThenReturn
-Hello
+Empty
 () throws IOExce
@@ -1635,18 +1635,16 @@
 ption %7B%0A
-//
         
@@ -1684,355 +1684,33 @@
 rn(%22
-Hello my friend%22,%0A//                String.format(%22Type something to send to Oracle%25sSending this line to the server...%25s%22 +%0A//                                %22Server ~ Hello my friend%25sSending this line to the server...%25sServer ~ null%25s%22,%0A//                        LN, LN, LN, LN, LN),%0A//                String.format(%22Hello%25sBye%22, LN)
+Bye%22, %22%22, %22Bye%22
 );%0A
-//
     %7D%0A
+%0A
     
@@ -1739,18 +1739,21 @@
 whenSend
-By
+Hello
 ThenRetu
@@ -1746,37 +1746,37 @@
 dHelloThenReturn
-Empty
+Hello
 () throws IOExce
@@ -1844,16 +1844,21 @@
  friend%22
+ + LN
 , %22Hello
@@ -1907,93 +1907,8 @@
 N));
-%0A    %7D%0A%0A    @Test%0A    public void whenSendHelloThenReturnHello() throws IOException %7B
 %0A%0A  

change whenSendHelloThenReturnHello