From adeef73a97cf191301a7b563883a075caed733b7 Mon Sep 17 00:00:00 2001 From: Damien Martin-Guillerez Date: Tue, 24 Mar 2015 09:05:08 +0000 Subject: Move all examples into Bazel workspace Those examples will be used for Bazel integration tests and their sources should be available directly to the Bazel workspace itself. -- MOS_MIGRATED_REVID=89380736 --- .../com/example/myproject/TestCustomGreeting.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/java-native/src/test/java/com/example/myproject/TestCustomGreeting.java (limited to 'examples/java-native/src/test/java/com/example/myproject/TestCustomGreeting.java') diff --git a/examples/java-native/src/test/java/com/example/myproject/TestCustomGreeting.java b/examples/java-native/src/test/java/com/example/myproject/TestCustomGreeting.java new file mode 100644 index 0000000000..f14b7d234a --- /dev/null +++ b/examples/java-native/src/test/java/com/example/myproject/TestCustomGreeting.java @@ -0,0 +1,32 @@ +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 using a resource file to replace "Hello" in the output. + */ +public class TestCustomGreeting { + + @Test + public void testNoArgument() throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Greeter.out = new PrintStream(out); + Greeter.main(); + assertEquals("Bye world\n", new String(out.toByteArray(), StandardCharsets.UTF_8)); + } + + @Test + public void testWithArgument() throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Greeter.out = new PrintStream(out); + Greeter.main("toto"); + assertEquals("Bye toto\n", new String(out.toByteArray(), StandardCharsets.UTF_8)); + } + +} -- cgit v1.2.3