aboutsummaryrefslogtreecommitdiffhomepage
path: root/base_workspace/examples/javatests
diff options
context:
space:
mode:
Diffstat (limited to 'base_workspace/examples/javatests')
-rw-r--r--base_workspace/examples/javatests/BUILD32
-rw-r--r--base_workspace/examples/javatests/test/Fail.java11
-rw-r--r--base_workspace/examples/javatests/test/TestBye.java29
-rw-r--r--base_workspace/examples/javatests/test/TestHello.java29
4 files changed, 101 insertions, 0 deletions
diff --git a/base_workspace/examples/javatests/BUILD b/base_workspace/examples/javatests/BUILD
new file mode 100644
index 0000000000..c504b1c7a0
--- /dev/null
+++ b/base_workspace/examples/javatests/BUILD
@@ -0,0 +1,32 @@
+java_test(
+ name = "hello",
+ srcs = ["test/TestHello.java"],
+ deps = [
+ "//examples/java:hello-lib",
+ "//third_party:junit4",
+ ],
+)
+
+java_test(
+ name = "bye",
+ srcs = ["test/TestBye.java"],
+ deps = [
+ "//examples/java:bye-lib",
+ "//third_party:junit4",
+ ],
+)
+
+java_test(
+ name = "fail",
+ srcs = ["test/Fail.java"],
+ deps = ["//third_party:junit4"],
+)
+
+java_test(
+ name = "should_fail",
+ srcs = glob(["test/Test*.java"]),
+ deps = [
+ "//examples/java:hello-lib",
+ "//third_party:junit4",
+ ],
+)
diff --git a/base_workspace/examples/javatests/test/Fail.java b/base_workspace/examples/javatests/test/Fail.java
new file mode 100644
index 0000000000..10e99210ff
--- /dev/null
+++ b/base_workspace/examples/javatests/test/Fail.java
@@ -0,0 +1,11 @@
+package test;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class Fail {
+ @Test
+ public void testFail() {
+ Assert.fail("This is an expected test failure.");
+ }
+}
diff --git a/base_workspace/examples/javatests/test/TestBye.java b/base_workspace/examples/javatests/test/TestBye.java
new file mode 100644
index 0000000000..2c00ce6e6c
--- /dev/null
+++ b/base_workspace/examples/javatests/test/TestBye.java
@@ -0,0 +1,29 @@
+package test;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
+
+public class TestBye {
+
+ @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));
+ }
+
+}
diff --git a/base_workspace/examples/javatests/test/TestHello.java b/base_workspace/examples/javatests/test/TestHello.java
new file mode 100644
index 0000000000..d121f96c27
--- /dev/null
+++ b/base_workspace/examples/javatests/test/TestHello.java
@@ -0,0 +1,29 @@
+package test;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
+
+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));
+ }
+
+}