diff options
author | 2015-03-24 09:05:08 +0000 | |
---|---|---|
committer | 2015-03-24 16:41:48 +0000 | |
commit | adeef73a97cf191301a7b563883a075caed733b7 (patch) | |
tree | c06734cbffa4160b156779da7c87dbf5cc2b6f94 /examples/java-native/src/test/java/com/example/myproject/TestHello.java | |
parent | 5247ff53465afc6ad9db889d1ec3f106ec09a3d6 (diff) |
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
Diffstat (limited to 'examples/java-native/src/test/java/com/example/myproject/TestHello.java')
-rw-r--r-- | examples/java-native/src/test/java/com/example/myproject/TestHello.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/java-native/src/test/java/com/example/myproject/TestHello.java b/examples/java-native/src/test/java/com/example/myproject/TestHello.java new file mode 100644 index 0000000000..d50e6e503f --- /dev/null +++ b/examples/java-native/src/test/java/com/example/myproject/TestHello.java @@ -0,0 +1,35 @@ +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\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("Hello toto\n", new String(out.toByteArray(), StandardCharsets.UTF_8)); + } + +} |