package com.sleekbyte.tailor.functional;

import com.sleekbyte.tailor.Tailor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * Base class for functional rule tests
 */
public abstract class RuleTest {

    protected static final String TEST_INPUT_DIR = "src/test/java/com/sleekbyte/tailor/functional/";
    protected static final String NEWLINE_REGEX = "\\r?\\n";

    protected ByteArrayOutputStream outContent;
    protected File inputFile;
    protected Set<String> expectedMessages;

    protected abstract void addAllExpectedMsgs();
    protected abstract String getInputFilePath();

    @Before
    public void setUp() {
        inputFile = new File(TEST_INPUT_DIR + getInputFilePath());
        expectedMessages = new HashSet<>();
        outContent = new ByteArrayOutputStream();
        System.setOut(new PrintStream(outContent));
    }

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

    @Test
    public void testRule() throws IOException {
        String[] command = getCommandArgs();
        addAllExpectedMsgs();

        Tailor.main(command);

        Set<String> actualOutput = new HashSet<>();
        for (String msg : outContent.toString().split(NEWLINE_REGEX)) {
            String truncatedMsg = msg.substring(msg.indexOf(inputFile.getName()));
            actualOutput.add(truncatedMsg);
        }

        assertEquals(expectedMessages.size(), actualOutput.size());
        assertTrue(actualOutput.containsAll(expectedMessages));
    }

    protected String[] getCommandArgs() {
        return new String[]{ inputFile.getPath() };
    }

}

@@ -280,37 +280,9 @@
 til.
-HashSet;%0Aimport java.util.Set
+*
 ;%0A%0Ai
@@ -706,18 +706,19 @@
 otected 
-Se
+Lis
 t%3CString
@@ -971,30 +971,32 @@
 sages = new 
-HashSe
+ArrayLis
 t%3C%3E();%0A     
@@ -1348,18 +1348,19 @@
         
-Se
+Lis
 t%3CString
@@ -1384,14 +1384,16 @@
 new 
-HashSe
+ArrayLis
 t%3C%3E(
@@ -1696,49 +1696,180 @@
 rue(
-actualOutput.containsAll(expectedMessages
+Arrays.equals(%0A                expectedMessages.toArray(new String%5BexpectedMessages.size()%5D),%0A                actualOutput.toArray(new String%5BactualOutput.size()%5D)%0A        
 ));%0A

Update RuleTest.java to test for sorted output