-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCalculatorTest.java
59 lines (39 loc) · 1.37 KB
/
CalculatorTest.java
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
47
48
49
50
51
52
53
54
55
56
57
58
59
import org.assertj.core.api.ThrowableAssert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
public class CalculatorTest {
private Calculator calculator;
private NumberProvider numberProvider;
@Before
public void setUp() {
this.numberProvider = Mockito.mock(NumberProvider.class);
this.calculator = new Calculator(10, numberProvider);
}
@Test
public void add_whenGive5_shouldReturn15() {
int b = 5;
int sum = this.calculator.add(b);
assertThat(sum).isEqualTo(15);
}
@Test
public void divide_whenGive2_shouldReturn5() {
int b = 2;
float quotient = this.calculator.divide(b);
assertThat(quotient).isEqualTo(5);
}
@Test
public void divide_whenGive0_shouldThrowIllegalArgumentException() {
int b = 0;
ThrowableAssert.ThrowingCallable method = () -> this.calculator.divide(b);
assertThatIllegalArgumentException().isThrownBy(method);
}
@Test
public void addToNumber_whenProvide1_shouldReturn11() {
Mockito.when(this.numberProvider.provideNumber()).thenReturn(1);
int sum = this.calculator.addToNumber();
assertThat(sum).isEqualTo(11);
}
}