summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--junit/01-simple/.gitignore2
-rw-r--r--junit/01-simple/.mvn/jvm.config0
-rw-r--r--junit/01-simple/.mvn/maven.config0
-rw-r--r--junit/01-simple/pom.xml90
-rw-r--r--junit/01-simple/src/main/java/com/example/myapp/App.java10
-rw-r--r--junit/01-simple/src/test/java/com/example/myapp/AppTest.java19
-rw-r--r--junit/02-maths/.gitignore2
-rw-r--r--junit/02-maths/.mvn/jvm.config0
-rw-r--r--junit/02-maths/.mvn/maven.config0
-rw-r--r--junit/02-maths/pom.xml90
-rw-r--r--junit/02-maths/src/main/java/com/example/maths/Maths.java16
-rw-r--r--junit/02-maths/src/test/java/com/example/maths/MathsTest.java32
12 files changed, 261 insertions, 0 deletions
diff --git a/junit/01-simple/.gitignore b/junit/01-simple/.gitignore
new file mode 100644
index 0000000..4e3ee4c
--- /dev/null
+++ b/junit/01-simple/.gitignore
@@ -0,0 +1,2 @@
+.vscode
+target
diff --git a/junit/01-simple/.mvn/jvm.config b/junit/01-simple/.mvn/jvm.config
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/junit/01-simple/.mvn/jvm.config
diff --git a/junit/01-simple/.mvn/maven.config b/junit/01-simple/.mvn/maven.config
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/junit/01-simple/.mvn/maven.config
diff --git a/junit/01-simple/pom.xml b/junit/01-simple/pom.xml
new file mode 100644
index 0000000..d5bf4b5
--- /dev/null
+++ b/junit/01-simple/pom.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.example.myapp</groupId>
+ <artifactId>simple</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <name>simple</name>
+ <!-- FIXME change it to the project's website -->
+ <url>http://www.example.com</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.release>25</maven.compiler.release>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.junit</groupId>
+ <artifactId>junit-bom</artifactId>
+ <version>5.11.0</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- Optionally: parameterized tests support -->
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
+ <plugins>
+ <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>3.4.0</version>
+ </plugin>
+ <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>3.3.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.13.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>3.3.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.4.2</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>3.1.2</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>3.1.2</version>
+ </plugin>
+ <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
+ <plugin>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>3.12.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>3.6.1</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/junit/01-simple/src/main/java/com/example/myapp/App.java b/junit/01-simple/src/main/java/com/example/myapp/App.java
new file mode 100644
index 0000000..7a68705
--- /dev/null
+++ b/junit/01-simple/src/main/java/com/example/myapp/App.java
@@ -0,0 +1,10 @@
+package com.example.myapp;
+
+/**
+ * Hello world!
+ */
+public class App {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/junit/01-simple/src/test/java/com/example/myapp/AppTest.java b/junit/01-simple/src/test/java/com/example/myapp/AppTest.java
new file mode 100644
index 0000000..49a35aa
--- /dev/null
+++ b/junit/01-simple/src/test/java/com/example/myapp/AppTest.java
@@ -0,0 +1,19 @@
+package com.example.myapp;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest {
+
+ /**
+ * Rigorous Test :-)
+ */
+ @Test
+ public void shouldAnswerWithTrue() {
+ assertTrue(true);
+ }
+}
diff --git a/junit/02-maths/.gitignore b/junit/02-maths/.gitignore
new file mode 100644
index 0000000..4e3ee4c
--- /dev/null
+++ b/junit/02-maths/.gitignore
@@ -0,0 +1,2 @@
+.vscode
+target
diff --git a/junit/02-maths/.mvn/jvm.config b/junit/02-maths/.mvn/jvm.config
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/junit/02-maths/.mvn/jvm.config
diff --git a/junit/02-maths/.mvn/maven.config b/junit/02-maths/.mvn/maven.config
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/junit/02-maths/.mvn/maven.config
diff --git a/junit/02-maths/pom.xml b/junit/02-maths/pom.xml
new file mode 100644
index 0000000..bba20e1
--- /dev/null
+++ b/junit/02-maths/pom.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.example.maths</groupId>
+ <artifactId>demo</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <name>demo</name>
+ <!-- FIXME change it to the project's website -->
+ <url>http://www.example.com</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.release>25</maven.compiler.release>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.junit</groupId>
+ <artifactId>junit-bom</artifactId>
+ <version>5.11.0</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- Optionally: parameterized tests support -->
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
+ <plugins>
+ <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>3.4.0</version>
+ </plugin>
+ <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>3.3.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.13.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>3.3.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.4.2</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>3.1.2</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>3.1.2</version>
+ </plugin>
+ <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
+ <plugin>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>3.12.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>3.6.1</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/junit/02-maths/src/main/java/com/example/maths/Maths.java b/junit/02-maths/src/main/java/com/example/maths/Maths.java
new file mode 100644
index 0000000..aac3ac0
--- /dev/null
+++ b/junit/02-maths/src/main/java/com/example/maths/Maths.java
@@ -0,0 +1,16 @@
+package com.example.maths;
+
+public class Maths {
+
+ public int factorial(int number) {
+ if (number == 0) {
+ return 1;
+ }
+
+ return number * factorial(number - 1);
+ }
+
+ public int divide(int a, int b) {
+ return a / b;
+ }
+}
diff --git a/junit/02-maths/src/test/java/com/example/maths/MathsTest.java b/junit/02-maths/src/test/java/com/example/maths/MathsTest.java
new file mode 100644
index 0000000..4396901
--- /dev/null
+++ b/junit/02-maths/src/test/java/com/example/maths/MathsTest.java
@@ -0,0 +1,32 @@
+package com.example.maths;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class MathsTest {
+ private Maths maths;
+
+ @BeforeEach
+ void setUp() {
+ maths = new Maths();
+ }
+
+ @Test
+ void testFactorial() {
+ assertEquals(1, maths.factorial(0), "Factorial of 0");
+ assertEquals(1, maths.factorial(1), "Factorial of 1");
+ assertEquals(120, maths.factorial(5), "Factorial of 5");
+ }
+
+ @Test
+ void testDivideByZeroThrowsException() {
+ ArithmeticException exception = assertThrows(ArithmeticException.class, () -> {
+ maths.divide(10, 0);
+ });
+
+ assertEquals("/ by zero", exception.getMessage());
+ }
+} \ No newline at end of file