-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserTest.java
executable file
·97 lines (78 loc) · 2.6 KB
/
UserTest.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.FileNotFoundException;
import javax.swing.JOptionPane;
/**
* The test class UserTest. Test's user input
*
* @author (Jesse Nelson)
* @version (October 6, 2012 : Windows 7(x64) Java1.7)
*/
public class UserTest {
User U;
Dictionary D;
String userInput;
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
@Before
public void setUp() {
U = new User();
D = null;
userInput = "";
}
@Test
public void dictionarySetUpTest() {
try {
D = U.dictionarySetUp();
} catch(FileNotFoundException e) {
fail("Default dictionary should have been loaded");
}
catch(Exception e) {
fail("dictionarySetUp threw incorrect Exception");
}
assertNotNull(D);
assertEquals(D.getClass(), Dictionary.class);
try {
D = U.dictionarySetUp();
} catch(FileNotFoundException e) {
fail("Unable to locate the selected file");
}
catch(Exception e) {
fail("dictionarySetUp threw incorrect Exception");
}
assertNotNull(D);
assertEquals(D.getClass(), Dictionary.class);
}
@Test
public void numberOfGuessesTest() {
userInput = JOptionPane.showInputDialog ("Enter 7");
assertEquals(7, Integer.parseInt(userInput));
userInput = JOptionPane.showInputDialog ("Enter 5");
assertEquals(5, Integer.parseInt(userInput));
userInput = JOptionPane.showInputDialog ("Enter 8");
assertEquals(8, Integer.parseInt(userInput));
}
@Test
public void WordLengthTest() {
userInput = JOptionPane.showInputDialog ("Enter 7");
assertEquals(7, Integer.parseInt(userInput));
userInput = JOptionPane.showInputDialog ("Enter 5");
assertEquals(5, Integer.parseInt(userInput));
userInput = JOptionPane.showInputDialog ("Enter 8");
assertEquals(8, Integer.parseInt(userInput));
}
@Test
public void showGame() {
userInput = JOptionPane.showInputDialog ("Enter a");
assertEquals('a', userInput.toLowerCase().charAt(0));
userInput = JOptionPane.showInputDialog ("Enter b");
assertEquals('b', userInput.toLowerCase().charAt(0));
userInput = JOptionPane.showInputDialog ("Enter c");
assertEquals('c', userInput.toLowerCase().charAt(0));
}
}