Repository navigation
Expand file tree
/
Copy pathSnakeTest.java
More file actions
70 lines (53 loc) · 1.93 KB
/
Copy pathSnakeTest.java
File metadata and controls
70 lines (53 loc) · 1.93 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
package com.battlesnake.starter;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SnakeTest {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
static {
OBJECT_MAPPER.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
}
private Snake.Handler handler;
@BeforeEach
void setUp() {
handler = new Snake.Handler();
}
@Test
void indexTest() throws IOException {
Map<String, String> response = handler.index();
assertEquals("#888888", response.get("color"));
assertEquals("default", response.get("headType"));
assertEquals("default", response.get("tailType"));
}
@Test
void startTest() throws IOException {
JsonNode startRequest = OBJECT_MAPPER.readTree("{}");
Map<String, String> response = handler.end(startRequest);
assertEquals(0, response.size());
}
@Test
void moveTest() throws IOException {
JsonNode moveRequest = OBJECT_MAPPER.readTree("{}");
Map<String, String> response = handler.move(moveRequest);
List<String> options = new ArrayList<String>();
options.add("up");
options.add("down");
options.add("left");
options.add("right");
assertTrue(options.contains(response.get("move")));
}
@Test
void endTest() throws IOException {
JsonNode endRequest = OBJECT_MAPPER.readTree("{}");
Map<String, String> response = handler.end(endRequest);
assertEquals(0, response.size());
}
}