-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathStringCalculatorTest.java
More file actions
46 lines (37 loc) · 1.25 KB
/
StringCalculatorTest.java
File metadata and controls
46 lines (37 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package calculator;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
public class StringCalculatorTest {
@Test
public void add() {
int result = StringCalculator.calculate("1 + 2 + 3");
assertThat(result).isEqualTo(6);
}
@Test
public void subtract() {
int result = StringCalculator.calculate("10 - 2 - 3");
assertThat(result).isEqualTo(5);
}
@Test
public void multiply() {
int result = StringCalculator.calculate("2 * 3 * 4");
assertThat(result).isEqualTo(24);
}
@Test
public void divide() {
int result = StringCalculator.calculate("10 / 2");
assertThat(result).isEqualTo(5);
}
@ParameterizedTest
@NullAndEmptySource
public void blankInput(String input) {
assertThatIllegalArgumentException().isThrownBy(() -> StringCalculator.calculate(input));
}
@Test
public void invalidOperation() {
assertThatIllegalArgumentException().isThrownBy(() -> StringCalculator.calculate("1 % 2"));
}
}