unit test
Scenario 1: Banking Application - Interest Calculation Function
//InterestCalculator.java
public class InterestCalculator {
public static double calculateInterest(double principal, double rate, double time) {
if (principal < 0 || rate < 0 || time < 0) {
throw new IllegalArgumentException("Principal, rate, and time must be non-negative");
return (principal * rate * time) / 100;
//InterestCalculatorTest.java
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class InterestCalculatorTest {
@Test
void testInterestCalculation() {
assertEquals(50.0, InterestCalculator.calculateInterest(1000, 5, 1));
@Test
void testZeroValues() {
assertEquals(0.0, InterestCalculator.calculateInterest(0, 5, 1));
}
@Test
void testNegativeValues() {
assertThrows(IllegalArgumentException.class, () -> InterestCalculator.calculateInterest(-1000, 5,
1));
assertThrows(IllegalArgumentException.class, () -> InterestCalculator.calculateInterest(1000, -5,
1));
assertThrows(IllegalArgumentException.class, () -> InterestCalculator.calculateInterest(1000, 5, -
1));