Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import junit.framework.TestCase;
- import java.io.ByteArrayOutputStream;
- import java.io.PrintStream;
- public class HelloWorldTest extends TestCase {
- private static final String NL = System.lineSeparator();
- public void testHelloWorld_NoCommandLineParamaters() {
- assertEquals("Hello world!" + NL, callMainMethod(new String[]{}));
- }
- public void testHelloJeff() {
- assertEquals("Hello Jeff!" + NL, callMainMethod(new String[]{"Jeff"}));
- }
- public void testHelloAlan() {
- assertEquals("Hello Alan!" + NL, callMainMethod(new String[]{"Alan"}));
- }
- public void testHelloAlanHolub() {
- assertEquals("Hello Alan Holub!" + NL, callMainMethod(new String[]{"Alan", "Holub"}));
- }
- public void test9parms() {
- assertEquals(
- "Hello 1 2 3 4 5 6 7 8 9!" + NL,
- callMainMethod(new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}));
- }
- private static String callMainMethod(final String[] args) {
- final var oldSystemOut = System.out;
- final var outputStream = new ByteArrayOutputStream();
- System.setOut(new PrintStream(outputStream));
- try {
- HelloWorld.main(args);
- } finally {
- System.setOut(oldSystemOut);
- }
- return outputStream.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement