diff options
author | 2015-02-20 15:45:07 +0000 | |
---|---|---|
committer | 2015-02-20 15:45:07 +0000 | |
commit | 254aee40df78e79ac1b19fe6d20ae20bb05129a8 (patch) | |
tree | 2a94af911e09d62782086b56e1d63b501714b843 /base_workspace/examples/java-native/src/test/java/com/example/myproject/TestHello.java | |
parent | 24e957158dad847c7a61fc40e49b7eae04335a67 (diff) |
Improve Java examples
--
MOS_MIGRATED_REVID=86787893
Diffstat (limited to 'base_workspace/examples/java-native/src/test/java/com/example/myproject/TestHello.java')
-rw-r--r-- | base_workspace/examples/java-native/src/test/java/com/example/myproject/TestHello.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/base_workspace/examples/java-native/src/test/java/com/example/myproject/TestHello.java b/base_workspace/examples/java-native/src/test/java/com/example/myproject/TestHello.java new file mode 100644 index 0000000000..d50e6e503f --- /dev/null +++ b/base_workspace/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)); + } + +} |