diff --git a/.gitignore b/.gitignore index 64d49ae..72bb427 100644 --- a/.gitignore +++ b/.gitignore @@ -213,4 +213,11 @@ marimo/_lsp/ __marimo__/ # Streamlit -.streamlit/secrets.toml \ No newline at end of file +.streamlit/secrets.toml + +# Java / Maven +*.class +*.jar +*.war +*.ear +java-hello-world/target/ \ No newline at end of file diff --git a/java-hello-world/pom.xml b/java-hello-world/pom.xml new file mode 100644 index 0000000..64216cd --- /dev/null +++ b/java-hello-world/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + com.example + java-hello-world + 1.0.0 + jar + + Java Hello World + A simple Java Hello World demo project + + + 17 + 17 + UTF-8 + 5.10.2 + + + + + org.junit.jupiter + junit-jupiter + ${junit.version} + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + + + com.example.HelloWorld + + + + + + + diff --git a/java-hello-world/src/main/java/com/example/HelloWorld.java b/java-hello-world/src/main/java/com/example/HelloWorld.java new file mode 100644 index 0000000..e8a7cbc --- /dev/null +++ b/java-hello-world/src/main/java/com/example/HelloWorld.java @@ -0,0 +1,15 @@ +package com.example; + +public class HelloWorld { + + public static String greet(String name) { + if (name == null || name.isBlank()) { + name = "World"; + } + return "Hello, " + name + "!"; + } + + public static void main(String[] args) { + System.out.println(greet("World")); + } +} diff --git a/java-hello-world/src/test/java/com/example/HelloWorldTest.java b/java-hello-world/src/test/java/com/example/HelloWorldTest.java new file mode 100644 index 0000000..5311b6c --- /dev/null +++ b/java-hello-world/src/test/java/com/example/HelloWorldTest.java @@ -0,0 +1,27 @@ +package com.example; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +class HelloWorldTest { + + @Test + void greetWorld() { + assertEquals("Hello, World!", HelloWorld.greet("World")); + } + + @Test + void greetCustomName() { + assertEquals("Hello, Java!", HelloWorld.greet("Java")); + } + + @Test + void greetNullFallsBackToWorld() { + assertEquals("Hello, World!", HelloWorld.greet(null)); + } + + @Test + void greetBlankFallsBackToWorld() { + assertEquals("Hello, World!", HelloWorld.greet(" ")); + } +}