-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordManagerTest.java
More file actions
74 lines (65 loc) · 2.22 KB
/
Copy pathWordManagerTest.java
File metadata and controls
74 lines (65 loc) · 2.22 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package org.cis1200.hangman;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
public class WordManagerTest {
@Test
public void wordManagerFilePathNull() {
assertThrows(IllegalArgumentException.class, () -> {
String filePath = null;
WordManager wm = new WordManager(filePath);
});
}
@Test
public void wordManagerFilePathEmpty() {
assertThrows(IllegalArgumentException.class, () -> {
String filePath = "";
WordManager wm = new WordManager(filePath);
});
}
@Test
public void wordManagerFilePathNonexistent() {
String filePath = "files/bank.txt";
WordManager wm = new WordManager(filePath);
assertDoesNotThrow(() -> wm, "THERE IS AN ERROR.");
}
@Test
public void wordManagerWordListCopiesCorrectly() {
String filePath = "files/dictionary.txt";
WordManager wm = new WordManager(filePath);
assertDoesNotThrow(() -> wm);
}
@Test
public void getRandomWordTest() {
WordManager wm = new WordManager("files/dictionary.txt");
String s = wm.getRandomWord().toLowerCase();
assertTrue(WordManager.wordsList.contains(s));
}
@Test
public void hideWordTestNormal() {
WordManager wm = new WordManager("files/dictionary.txt");
String s = wm.getRandomWord();
String hiddenS = WordManager.hideWord(s);
int i = s.length();
String expected = "";
for (int x = 0; x < i; x++) {
expected += "?";
}
assertEquals(expected, hiddenS);
}
@Test
public void hideWordTestWordNull() {
assertThrows(IllegalArgumentException.class, () -> {
WordManager wm = new WordManager("files/dictionary.txt");
String s = null;
String hiddenS = wm.hideWord(s);
});
}
@Test
public void hideWordTestWordEmpty() {
assertThrows(IllegalArgumentException.class, () -> {
WordManager wm = new WordManager("files/dictionary.txt");
String s = "";
String hiddenS = wm.hideWord(s);
});
}
}