Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,25 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<argLine>
-javaagent:${com.ginsberg:junit5-system-exit:jar}
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -212,9 +227,14 @@
<dependency>
<groupId>com.ginsberg</groupId>
<artifactId>junit5-system-exit</artifactId>
<version>1.0.0</version>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>edu.iris.dmc</groupId>
<artifactId>java-4-seed</artifactId>
<version>1.1.0</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
155 changes: 76 additions & 79 deletions src/test/java/edu/iris/dmc/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}