JeffGrigg icon

Untitled

JeffGrigg | PRO | 04/03/21 12:52:12 AM UTC | 0 ⭐ | 12259 👁️ | Never ⏰ | []
Java 5 |

0 B

|

None

|

0 👍

/

0 👎

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();
    }
 
}
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎