0% found this document useful (0 votes)
17 views2 pages

Unit Test 126015031

The document contains a Java class for calculating interest in a banking application, with a method that throws an exception for negative inputs. It also includes a set of unit tests to verify the functionality of the interest calculation method, including tests for valid, zero, and negative values. The tests ensure that the method behaves correctly under various scenarios.

Uploaded by

jaswanthi.gowru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Unit Test 126015031

The document contains a Java class for calculating interest in a banking application, with a method that throws an exception for negative inputs. It also includes a set of unit tests to verify the functionality of the interest calculation method, including tests for valid, zero, and negative values. The tests ensure that the method behaves correctly under various scenarios.

Uploaded by

jaswanthi.gowru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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));

You might also like