-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathGameTest.java
More file actions
42 lines (32 loc) · 1.2 KB
/
GameTest.java
File metadata and controls
42 lines (32 loc) · 1.2 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
package game;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
public class GameTest {
Game game = new Game();
@Test
void testRandomNumberSizeIs3() throws Exception {
Method method = Game.class.getDeclaredMethod("makeRandomNumber");
method.setAccessible(true);
Field field = Game.class.getDeclaredField("answer");
field.setAccessible(true);
ArrayList<Integer> array = (ArrayList<Integer>)field.get(game);
method.invoke(game);
assertThat(array.size()).isEqualTo(3);
}
@Test
void testRandomNumberIsNotDuplicated() throws Exception {
Method method = Game.class.getDeclaredMethod("makeRandomNumber");
method.setAccessible(true);
Field field = Game.class.getDeclaredField("answer");
field.setAccessible(true);
ArrayList<Integer> array = (ArrayList<Integer>)field.get(game);
method.invoke(game);
Set<Integer> set = new HashSet<>(array);
assertThat(set.size()).isEqualTo(array.size());
}
}