summaryrefslogtreecommitdiff
path: root/junit/02-maths/src/test
diff options
context:
space:
mode:
authorKamal Wickramanayake <kamal@inbox.lk>2026-06-27 17:10:54 +0530
committerKamal Wickramanayake <kamal@inbox.lk>2026-06-27 17:10:54 +0530
commitd7ce2a3ea234de3a040e762083db88aa3610f320 (patch)
tree3708217efaca2c1cfebb1cebfe385bee722d6aea /junit/02-maths/src/test
parent65b05bc4932520ca2e31de92e3dc7a347b3b4968 (diff)
Added two JUnit sample apps
Diffstat (limited to 'junit/02-maths/src/test')
-rw-r--r--junit/02-maths/src/test/java/com/example/maths/MathsTest.java32
1 files changed, 32 insertions, 0 deletions
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