| package com.example.myproject; | 
 |  | 
 | import static org.junit.Assert.assertEquals; | 
 |  | 
 | import org.junit.Test; | 
 |  | 
 | import java.io.ByteArrayOutputStream; | 
 | import java.io.PrintStream; | 
 | import java.nio.charset.StandardCharsets; | 
 |  | 
 | /** | 
 |  * Tests different numbers of arguments to main(). | 
 |  * | 
 |  * <p>With an empty args array, {@link Greeter} should print "Hello world". If there are one or more | 
 |  * args, {@link Greeter} should print "Hello <arg[0]>".</p> | 
 |  */ | 
 | public class TestHello { | 
 |  | 
 |   @Test | 
 |   public void testNoArgument() throws Exception { | 
 |     ByteArrayOutputStream out = new ByteArrayOutputStream(); | 
 |     Greeter.out = new PrintStream(out); | 
 |     Greeter.main(); | 
 |     assertEquals("Hello world", new String(out.toByteArray(), StandardCharsets.UTF_8).trim()); | 
 |   } | 
 |  | 
 |   @Test | 
 |   public void testWithArgument() throws Exception { | 
 |     ByteArrayOutputStream out = new ByteArrayOutputStream(); | 
 |     Greeter.out = new PrintStream(out); | 
 |     Greeter.main("toto"); | 
 |     assertEquals("Hello toto", new String(out.toByteArray(), StandardCharsets.UTF_8).trim()); | 
 |   } | 
 |  | 
 | } |