Kristina Chodorow | 254aee4 | 2015-02-20 15:45:07 +0000 | [diff] [blame] | 1 | package com.example.myproject; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | |
| 3 | import static org.junit.Assert.assertEquals; |
| 4 | |
| 5 | import org.junit.Test; |
| 6 | |
| 7 | import java.io.ByteArrayOutputStream; |
| 8 | import java.io.PrintStream; |
| 9 | import java.nio.charset.StandardCharsets; |
| 10 | |
Kristina Chodorow | 254aee4 | 2015-02-20 15:45:07 +0000 | [diff] [blame] | 11 | /** |
| 12 | * Tests using a resource file to replace "Hello" in the output. |
| 13 | */ |
| 14 | public class TestCustomGreeting { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 15 | |
| 16 | @Test |
| 17 | public void testNoArgument() throws Exception { |
| 18 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 19 | Greeter.out = new PrintStream(out); |
| 20 | Greeter.main(); |
Yun Peng | ce79c81 | 2016-06-15 10:00:55 +0000 | [diff] [blame] | 21 | assertEquals("Bye world", new String(out.toByteArray(), StandardCharsets.UTF_8).trim()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | @Test |
| 25 | public void testWithArgument() throws Exception { |
| 26 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 27 | Greeter.out = new PrintStream(out); |
| 28 | Greeter.main("toto"); |
Yun Peng | ce79c81 | 2016-06-15 10:00:55 +0000 | [diff] [blame] | 29 | assertEquals("Bye toto", new String(out.toByteArray(), StandardCharsets.UTF_8).trim()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | } |