forked from TWU-C-Tech-Trainee/java-basic-exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrammarExerciseTest.java
More file actions
50 lines (43 loc) · 1.58 KB
/
GrammarExerciseTest.java
File metadata and controls
50 lines (43 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
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class GrammarExerciseTest {
GrammarExercise grammarExercise;
@BeforeEach
void setUp() {
grammarExercise = new GrammarExercise();
}
@Test
void should_return_common_words_with_space() {
//given
String first = "apple,juice,mother,people,beautiful,apple,dog";
String second = "cat,baby,smile,good,apple,beautiful,Dog,nice";
List<String> expected = Arrays.asList("A P P L E", "B E A U T I F U L", "D O G");
//when
List<String> result = grammarExercise.findCommonWordsWithSpace(first, second);
//then
assertIterableEquals(result, expected);
}
@Test
void should_throw_exception_when_input_has_two_comma() {
//given
String first = "apple,,juice,mother,people,beautiful,apple,dog";
String second = "cat,baby,smile,good,apple,beautiful,Dog,nice";
//when&then
assertThrows(RuntimeException.class, () -> {
grammarExercise.findCommonWordsWithSpace(first, second);
});
}
@Test
void should_throw_exception_when_input_contains_invalid_symbol() {
//given
String first = "apple,juice,mother,people,bea&&utiful,apple,dog";
String second = "cat,baby,smile,good,apple,bea&&utiful,Dog,nice";
//when&then
assertThrows(RuntimeException.class, () -> {
grammarExercise.findCommonWordsWithSpace(first, second);
});
}
}