package ru.matevosyan;

import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;


/**
 * Created SortFile for testing sort big file and write it to a new file.
 * Created on 19.02.2017.
 * @since 1.0
 * @author Matevosyan Vardan
 * @version 1.0
 */

public class ConsoleChatTest {

//    private ClassLoader classLoader = getClass().getClassLoader();
//    private static final String pathSource = "sourceFile.txt";
//    private static final String outPutPathSource = "outPutPathSourceFile.txt";
//    private File sourceFile = new File(classLoader.getResource(pathSource).getFile());
//    private File outPutPathSourceFile = new File(classLoader.getResource(outPutPathSource).getFile());
    private static final String stop = "STOP";
    private static final String cont = "CONTINUE";
    private static final String exit = "EXIT";


    /**
     * testing files size.
     */

    @Test
    public void whenGetSettingPropertiesThenReturnNameOfFiles() throws IOException {

        ClassLoader classLoader = Setting.class.getClassLoader();
        Setting setting = new Setting();

        try (InputStream resourceAsStream = classLoader.getResourceAsStream("config.properties")) {
            setting.load(resourceAsStream);
        }

        String readFile = setting.getValue("pathSource.txt");
        String writeFile = setting.getValue("outPutPathSource.txt");

        assertThat(readFile , is("pathSource.txt"));
        assertThat(writeFile , is("outPutPathSource.txt"));
    }

    @Test
    public void whenGetThenReturn() throws IOException {

        ClassLoader classLoader = Setting.class.getClassLoader();
        Setting setting = new Setting();

        try (InputStream resourceAsStream = classLoader.getResourceAsStream("config.properties")) {
            setting.load(resourceAsStream);
        }

        String readFileName = setting.getValue("pathSource.txt");
        String writeFileName = setting.getValue("outPutPathSource.txt");

        File readFile = new File(readFileName);
        File writeFile = new File(writeFileName);

        String s = System.getProperty("line.separator");
        String consoleInput = String.format("%s%s%s", "Hello", s, "EXIT");

        ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(consoleInput.getBytes());
        System.setIn(arrayInputStream);

        ConsoleChat consoleChat = new ConsoleChat(readFile, writeFile);
        consoleChat.readUserData();

        assertThat(readFile , is("pathSource.txt"));
        assertThat(writeFile , is("outPutPathSource.txt"));
    }
}
@@ -567,25 +567,25 @@
 urce = %22
-sourceFil
+pathSourc
 e.txt%22;%0A
@@ -1717,33 +1717,32 @@
 rows IOException
- 
 %7B%0A%0A        Class
@@ -2114,32 +2114,36 @@
 outPutPathSource
+File
 .txt%22);%0A%0A       
@@ -2147,48 +2147,156 @@
     
-File readFile = new File(readFileName
+String s = System.getProperty(%22line.separator%22);%0A%0A//        File readFile = new File(%22./src/main/resources%22 + File.separator + %22pathSource.txt%22
 );%0A
+//
     
@@ -2329,82 +2329,179 @@
 ile(
-writeFileName);%0A%0A        String s = System.getProperty(%22line.separator%22
+%22./src/main/resources%22 + File.separator + %22outPutPathSourceFile.txt%22);%0A%0A        File readFile = new File(readFileName);%0A        File writeFile = new File(writeFileName
 );%0A
+%0A
     
@@ -2547,16 +2547,20 @@
 (%22%25s%25s%25s
+%25s%25s
 %22, %22Hell
@@ -2565,16 +2565,35 @@
 llo%22, s,
+ %22How are you?%22, s,
  %22EXIT%22)
@@ -2863,32 +2863,42 @@
 ertThat(readFile
+.getName()
  , is(%22pathSourc
@@ -2927,32 +2927,42 @@
 rtThat(writeFile
+.getName()
  , is(%22outPutPat

change not work