-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArithmeticOperatorsTest.java
23 lines (19 loc) · 1.04 KB
/
ArithmeticOperatorsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.thebackendpro.junit5.exceptionstesting;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class ArithmeticOperatorsTest {
@Test
public void divisionTestWhenExceptionIsThrown() {
ArithmeticOperators arithmeticOperators = new ArithmeticOperators();
ArithmeticException arithmeticException = Assertions.assertThrows(ArithmeticException.class,
() -> arithmeticOperators.division(5, 0), "Failed due to no excpeption is thrown");
Assertions.assertEquals("Cannot divide a number by 0", arithmeticException.getMessage());
}
@Test
public void divisionTestWhenNoExceptionIsThrown() {
ArithmeticOperators arithmeticOperators = new ArithmeticOperators();
ArithmeticException arithmeticException = Assertions.assertThrows(ArithmeticException.class,
() -> arithmeticOperators.division(5, 1), "Failed due to no excpeption is thrown");
Assertions.assertEquals("Cannot divide a number by 0", arithmeticException.getMessage());
}
}