blob: 7bc55fc643576cb9765d6466055f438d628028cc [file] [log] [blame]
Kristina Chodorow254aee42015-02-20 15:45:07 +00001package com.example.myproject;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002
3import static org.junit.Assert.assertEquals;
4
5import org.junit.Test;
6
7import java.io.ByteArrayOutputStream;
8import java.io.PrintStream;
9import java.nio.charset.StandardCharsets;
10
Kristina Chodorow254aee42015-02-20 15:45:07 +000011/**
12 * Tests using a resource file to replace "Hello" in the output.
13 */
14public class TestCustomGreeting {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010015
16 @Test
17 public void testNoArgument() throws Exception {
18 ByteArrayOutputStream out = new ByteArrayOutputStream();
19 Greeter.out = new PrintStream(out);
20 Greeter.main();
Yun Pengce79c812016-06-15 10:00:55 +000021 assertEquals("Bye world", new String(out.toByteArray(), StandardCharsets.UTF_8).trim());
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010022 }
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 Pengce79c812016-06-15 10:00:55 +000029 assertEquals("Bye toto", new String(out.toByteArray(), StandardCharsets.UTF_8).trim());
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010030 }
31
32}