package com.sleekbyte.tailor.grammar;

import com.sleekbyte.tailor.Tailor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

import static org.junit.Assert.assertEquals;

@RunWith(MockitoJUnitRunner.class)
public class GrammarTest {

    private static final String TEST_INPUT_DIR = "src/test/java/com/sleekbyte/tailor/grammar/";

    private ByteArrayOutputStream errContent;
    private ByteArrayOutputStream outContent;
    private File[] swiftFiles;

    @Before
    public void setUp() throws UnsupportedEncodingException {
        File curDir = new File(TEST_INPUT_DIR);
        swiftFiles = curDir.listFiles((File file, String name) -> name.endsWith(".swift"));
        outContent = new ByteArrayOutputStream();
        System.setOut(new PrintStream(outContent, false, Charset.defaultCharset().name()));
    }

    @After
    public void tearDown() {
        System.setOut(null);
    }

    @Test
    public void testGrammar() throws UnsupportedEncodingException {
        for (File swiftFile: swiftFiles) {
            errContent = new ByteArrayOutputStream();
            System.setErr(new PrintStream(errContent, false, Charset.defaultCharset().name()));
            String[] command = { (TEST_INPUT_DIR + swiftFile.getName()) };
            Tailor.main(command);
            assertEquals("", errContent.toString(Charset.defaultCharset().name()));
            System.setErr(null);
        }
    }

}

@@ -68,16 +68,56 @@
 Tailor;%0A
+import org.hamcrest.text.IsEmptyString;%0A
 import o
@@ -464,22 +464,20 @@
 t.assert
-Equals
+That
 ;%0A%0A@RunW
@@ -1596,19 +1596,13 @@
 sert
-Equals(%22%22, 
+That(
 errC
@@ -1641,32 +1641,63 @@
 harset().name())
+, IsEmptyString.isEmptyString()
 );%0A            S

Use Hamcrest text Matcher in GrammarTest