// Path: src/main/java/org/jsoftware/tjconsole/console/Output.java
// public class Output implements Closeable {
//     private final Pattern ansiRemovePattern = Pattern.compile("(@\\|\\w* )|( ?\\|@)");
//     private final PrintStream out;
//     private boolean useColors = true, ansiInstalled, filterInfo;
// 
//     public Output(PrintStream out, boolean useColors) {
//         this.out = out;
//         setUseColors(useColors);
//     }
// 
//     public void setFilterInfo(boolean filterInfo) {
//         this.filterInfo = filterInfo;
//     }
// 
//     public boolean isUseColors() {
//         return useColors;
//     }
// 
// 
//     public void setUseColors(boolean useColors) {
//         this.useColors = useColors;
//         if (useColors) {
//             AnsiConsole.systemInstall();
//             ansiInstalled = true;
//         } else {
//             AnsiConsole.systemUninstall();
//             ansiInstalled = false;
//         }
//     }
// 
// 
//     public void print(String text) {
//         if (useColors) {
//             out.print(ansi().render(text));
//         } else {
//             String s = ansiRemovePattern.matcher(text).replaceAll("");
//             out.print(s);
//         }
//         out.flush();
//     }
// 
// 
//     public void println(String text) {
//         print(text);
//         out.println();
//         out.flush();
//     }
// 
// 
//     @Override
//     public void close() throws IOException {
//         if (ansiInstalled) {
//             AnsiConsole.systemUninstall();
//         }
//         out.close();
//     }
// 
//     public void outError(String text) {
//         println("@|red " + text + "|@");
//     }
// 
//     public void outInfo(String text) {
//         if (! filterInfo) {
//             println("@|cyan " + text + "|@");
//         }
//     }
// }


import org.jsoftware.tjconsole.console.Output;
import org.junit.Before;
import org.junit.Test;
import javax.management.MBeanServer;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.management.ManagementFactory;
import java.util.Properties;
import java.util.regex.Pattern;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
        tjConsole.executeCommand("env DATE_FORMAT=yyyy-MMM-dd", outputHelper.getOutput());
        outputHelper.clear();
        tjConsole.executeCommand("env", outputHelper.getOutput());
        System.out.println(outputHelper);
        assertTrue(outputHelper.toString().contains("DATE_FORMAT = yyyy-MMM-dd"));
    }

    @Test
    public void testCmdPs() throws Exception {
        Pattern processLinePattern = Pattern.compile("^\\d{1,} .*$");
        tjConsole.executeCommand("ps", outputHelper.getOutput());
        String[] processList = outputHelper.toString().trim().split("\n");
        int psCount = 0;
        for(String psLine : processList) {
            psLine = psLine.trim();
            if (psLine.length() == 0) {
                continue;
            }
            psCount++;
            if (! processLinePattern.matcher(psLine).matches()) {
                fail("Line '" + psLine + "' doesn't look like ps line!");
            }
        }
        assertTrue("We don't have even one process on the list", psCount > 0);
    }
}

class TestOutputHelper {
    private ByteArrayOutputStream out = new ByteArrayOutputStream();

// Path: src/main/java/org/jsoftware/tjconsole/console/Output.java
// public class Output implements Closeable {
//     private final Pattern ansiRemovePattern = Pattern.compile("(@\\|\\w* )|( ?\\|@)");
//     private final PrintStream out;
//     private boolean useColors = true, ansiInstalled, filterInfo;
// 
//     public Output(PrintStream out, boolean useColors) {
//         this.out = out;
//         setUseColors(useColors);
//     }
// 
//     public void setFilterInfo(boolean filterInfo) {
//         this.filterInfo = filterInfo;
//     }
// 
//     public boolean isUseColors() {
//         return useColors;
//     }
// 
// 
//     public void setUseColors(boolean useColors) {
//         this.useColors = useColors;
//         if (useColors) {
//             AnsiConsole.systemInstall();
//             ansiInstalled = true;
//         } else {
//             AnsiConsole.systemUninstall();
//             ansiInstalled = false;
//         }
//     }
// 
// 
//     public void print(String text) {
//         if (useColors) {
//             out.print(ansi().render(text));
//         } else {
//             String s = ansiRemovePattern.matcher(text).replaceAll("");
//             out.print(s);
//         }
//         out.flush();
//     }
// 
// 
//     public void println(String text) {
//         print(text);
//         out.println();
//         out.flush();
//     }
// 
// 
//     @Override
//     public void close() throws IOException {
//         if (ansiInstalled) {
//             AnsiConsole.systemUninstall();
//         }
//         out.close();
//     }
// 
//     public void outError(String text) {
//         println("@|red " + text + "|@");
//     }
// 
//     public void outInfo(String text) {
//         if (! filterInfo) {
//             println("@|cyan " + text + "|@");
//         }
//     }
// }


// Path: src/test/java/org/jsoftware/tjconsole/TJConsoleE2ETest.java
import org.jsoftware.tjconsole.console.Output;
import org.junit.Before;
import org.junit.Test;
import javax.management.MBeanServer;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.management.ManagementFactory;
import java.util.Properties;
import java.util.regex.Pattern;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

        tjConsole.executeCommand("env DATE_FORMAT=yyyy-MMM-dd", outputHelper.getOutput());
        outputHelper.clear();
        tjConsole.executeCommand("env", outputHelper.getOutput());
        System.out.println(outputHelper);
        assertTrue(outputHelper.toString().contains("DATE_FORMAT = yyyy-MMM-dd"));
    }

    @Test
    public void testCmdPs() throws Exception {
        Pattern processLinePattern = Pattern.compile("^\\d{1,} .*$");
        tjConsole.executeCommand("ps", outputHelper.getOutput());
        String[] processList = outputHelper.toString().trim().split("\n");
        int psCount = 0;
        for(String psLine : processList) {
            psLine = psLine.trim();
            if (psLine.length() == 0) {
                continue;
            }
            psCount++;
            if (! processLinePattern.matcher(psLine).matches()) {
                fail("Line '" + psLine + "' doesn't look like ps line!");
            }
        }
        assertTrue("We don't have even one process on the list", psCount > 0);
    }
}

class TestOutputHelper {
    private ByteArrayOutputStream out = new ByteArrayOutputStream();

    public Output getOutput() {