-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathValidatorTest.java
More file actions
55 lines (38 loc) · 1.58 KB
/
ValidatorTest.java
File metadata and controls
55 lines (38 loc) · 1.58 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
47
48
49
50
51
52
53
54
55
package calculator;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
class ValidatorTest {
Validator validator = new Validator();
@Test
void split_test() {
String input = "3+5*2";
List<String> result = validator.divideInput(input);
assertThat(result).containsExactly("3", "+", "5", "*", "2");
}
@Test
void exception_test_for_blank() {
String input = " ";
Exception e = assertThrows(IllegalStateException.class, () -> validator.divideInput(input));
assertThat(e.getMessage()).isEqualTo(Console.MESSAGE_ERROR_EMPTY_OR_BLANK);
}
@Test
void exception_test_for_operators() {
String input = "3++2";
Exception e = assertThrows(IllegalArgumentException.class, () -> validator.divideInput(input));
assertThat(e.getMessage()).isEqualTo(Console.MESSAGE_ERROR_WRONG_POSITION_OPERATORS);
}
@Test
void exception_test_for_input_format() {
String input = "5+a";
Exception e = assertThrows(IllegalArgumentException.class, () -> validator.divideInput(input));
assertThat(e.getMessage()).isEqualTo(Console.MESSAGE_ERROR_FORMAT);
}
@Test
void exception_test_for_first_starts_with_operator() {
String input = "+12+3-5";
Exception e = assertThrows(IllegalArgumentException.class, () -> validator.divideInput(input));
assertThat(e.getMessage()).isEqualTo(Console.MESSAGE_ERROR_WRONG_POSITION_OPERATORS);
}
}