From d7ce2a3ea234de3a040e762083db88aa3610f320 Mon Sep 17 00:00:00 2001 From: Kamal Wickramanayake Date: Sat, 27 Jun 2026 17:10:54 +0530 Subject: Added two JUnit sample apps --- .../src/test/java/com/example/maths/MathsTest.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 junit/02-maths/src/test/java/com/example/maths/MathsTest.java (limited to 'junit/02-maths/src/test/java') 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 -- cgit v1.2.3