diff --git a/pom.xml b/pom.xml
index e10b31d..1f97b52 100644
--- a/pom.xml
+++ b/pom.xml
@@ -108,10 +108,25 @@
+
+ maven-dependency-plugin
+
+
+
+ properties
+
+
+
+
org.apache.maven.plugins
maven-surefire-plugin
3.0.0-M4
+
+
+ -javaagent:${com.ginsberg:junit5-system-exit:jar}
+
+
org.apache.maven.plugins
@@ -212,9 +227,14 @@
com.ginsberg
junit5-system-exit
- 1.0.0
+ 2.0.2
test
+
+ edu.iris.dmc
+ java-4-seed
+ 1.1.0
+
org.junit.jupiter
diff --git a/src/test/java/edu/iris/dmc/MainTest.java b/src/test/java/edu/iris/dmc/MainTest.java
index f56368f..66404bd 100644
--- a/src/test/java/edu/iris/dmc/MainTest.java
+++ b/src/test/java/edu/iris/dmc/MainTest.java
@@ -3,91 +3,88 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
-import java.io.FileDescriptor;
-import java.io.FileOutputStream;
import java.io.PrintStream;
import java.net.URL;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
public class MainTest {
- // This class test the main method and its outputs.
-
- ByteArrayOutputStream outContent = new ByteArrayOutputStream();
- ByteArrayOutputStream newContent = new ByteArrayOutputStream();
-
-
- @Test
- public void mainTest() throws Exception{
- PrintStream ps = new PrintStream(outContent);
- PrintStream nerrps = new PrintStream(newContent);
- System.setOut(ps);
- System.setErr(nerrps);
- URL url = MainTest.class.getClassLoader().getResource("pass.xml");
- String[] args = new String[] {"--verbose","--ignore-warnings", "--input", url.getPath()};
- Application.main(args);
- System.setOut( new PrintStream( new FileOutputStream( FileDescriptor.out ) ) );
- String sysout = outContent.toString().replaceAll( "\r", "" );
- System.setErr( new PrintStream( new FileOutputStream( FileDescriptor.out ) ) );
- String syserr = newContent.toString().replaceAll( "\r", "" );
- outContent.close();
- newContent.close();
- nerrps.close();
- ps.close();
- //System.out.println(sysout.toString());
- System.out.println("+++++++++++++++++++++++++++");
- System.out.println(syserr.toString());
- boolean content1 = syserr.toString().contains("edu.iris.dmc.Application run:");
- boolean content2 = sysout.toString().contains("PASSED");
- boolean content3 = sysout.toString().contains("\n");
- //assertTrue(content1==true);
- assertTrue(content2==true);
- assertTrue(content3==true);
- }
-
- @Test
- @ExpectSystemExitWithStatus(0)
- public void help() throws Exception{
- //URL url = FileConverterRunner.class.getClassLoader().getResource("CU_ANWB_BH2.xml");
- PrintStream ps = new PrintStream(outContent);
- System.setOut(ps);
- String[] args = new String[] {"--help"};
- Application.main(args);
- System.setOut( new PrintStream( new FileOutputStream( FileDescriptor.out ) ) );
- outContent.close();
- ps.close();
-
- }
-
- @Test
- @ExpectSystemExitWithStatus(0)
- public void rules() throws Exception{
- //URL url = FileConverterRunner.class.getClassLoader().getResource("CU_ANWB_BH2.xml");
- PrintStream ps = new PrintStream(outContent);
- System.setOut(ps);
- String[] args = new String[] {"--rules"};
- Application.main(args);
- System.setOut( new PrintStream( new FileOutputStream( FileDescriptor.out ) ) );
- outContent.close();
- ps.close();
-
- }
-
- @Test
- @ExpectSystemExitWithStatus(0)
- public void units() throws Exception{
- //URL url = FileConverterRunner.class.getClassLoader().getResource("CU_ANWB_BH2.xml");
- PrintStream ps = new PrintStream(outContent);
- System.setOut(ps);
- String[] args = new String[] {"--units"};
- Application.main(args);
- System.setOut( new PrintStream( new FileOutputStream( FileDescriptor.out ) ) );
- outContent.close();
- ps.close();
-
- }
-
- }
+ private PrintStream originalOut;
+ private PrintStream originalErr;
+
+ @BeforeEach
+ void setUp() {
+ originalOut = System.out;
+ originalErr = System.err;
+ }
+
+ @AfterEach
+ void tearDown() {
+ System.setOut(originalOut);
+ System.setErr(originalErr);
+ }
+
+ @Test
+ public void mainTest() throws Exception {
+
+ ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+ ByteArrayOutputStream errContent = new ByteArrayOutputStream();
+
+ System.setOut(new PrintStream(outContent));
+ System.setErr(new PrintStream(errContent));
+
+ URL url = MainTest.class.getClassLoader().getResource("pass.xml");
+ String[] args = new String[] {
+ "--verbose",
+ "--ignore-warnings",
+ "--input",
+ url.getPath()
+ };
+
+ Application.main(args);
+
+ String sysout = outContent.toString().replace("\r", "");
+ String syserr = errContent.toString().replace("\r", "");
+
+ boolean content2 = sysout.contains("PASSED");
+ boolean content3 = sysout.contains("\n");
+
+ assertTrue(content2);
+ assertTrue(content3);
+ }
+
+ @Test
+ @ExpectSystemExitWithStatus(0)
+ public void help() throws Exception {
+ ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outContent));
+
+ String[] args = new String[] {"--help"};
+ Application.main(args);
+ }
+
+ @Test
+ @ExpectSystemExitWithStatus(0)
+ public void rules() throws Exception {
+ ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outContent));
+
+ String[] args = new String[] {"--rules"};
+ Application.main(args);
+ }
+
+ @Test
+ @ExpectSystemExitWithStatus(0)
+ public void units() throws Exception {
+ ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outContent));
+
+ String[] args = new String[] {"--units"};
+ Application.main(args);
+ }
+}