Cleaned up main() tests.

This commit is contained in:
Erik C. Thauvin 2021-03-17 12:26:47 -07:00
parent 3a64bd57d5
commit 41471e31af

View file

@ -34,12 +34,14 @@ package net.thauvin.erik.httpstatus;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
/** /**
@ -55,7 +57,7 @@ public class ReasonsMainTest {
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
@AfterTest @AfterTest
public void restoreStreams() { public void restoreStreams() {
System.setOut(originalOut); System.setOut(originalOut);
} }
@ -64,15 +66,36 @@ public class ReasonsMainTest {
System.setOut(new PrintStream(outContent)); System.setOut(new PrintStream(outContent));
} }
@BeforeMethod
public void resetStreams() {
outContent.reset();
}
@Test @Test
public void testMain() { public void testMain() {
Reasons.main("401"); Reasons.main("401");
assertTrue(outContent.toString().contains(Reasons.getReasonPhrase("401"))); assertTrue(outContent.toString().contains(Reasons.getReasonPhrase("401")), "401");
assertFalse(outContent.toString().contains("500"), "401 no 500");
} }
@Test @Test
public void testMainAll() { public void testMainAll() {
Reasons.main(); Reasons.main();
assertTrue(outContent.toString().contains(Reasons.getReasonPhrase(401))); assertTrue(outContent.toString().contains(Reasons.getReasonPhrase(301)), "301");
assertTrue(outContent.toString().contains(Reasons.getReasonPhrase(404)), "404");
} }
}
@Test
public void testMainArgs() {
Reasons.main("500", "302");
assertTrue(outContent.toString().contains(Reasons.getReasonPhrase("500")), "500 (302)");
assertTrue(outContent.toString().contains(Reasons.getReasonPhrase("302")), "(500) 302");
assertFalse(outContent.toString().contains("404"), "500/302 not 404");
}
@Test
public void testMainInvalid() {
Reasons.main("aaa");
assertTrue(outContent.toString().isEmpty(), "invalid argument: aaa");
}
}