-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJSONparserTest.java
More file actions
50 lines (40 loc) · 1.47 KB
/
JSONparserTest.java
File metadata and controls
50 lines (40 loc) · 1.47 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
package com.queststore.Services;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import com.sun.net.httpserver.HttpExchange;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class JSONparserTest {
private JSONparser jsonParser;
@BeforeEach
void setup() {
jsonParser = new JSONparser();
}
@AfterEach
void tearDown() {
jsonParser = null;
}
@Test
void parseJSONlistToArray() throws java.io.IOException {
String json = "[\n" +
" \"my/path/old\",\n" +
" \"my/path/new\"\n" +
" ]";
System.out.println(jsonParser.parseJSONlistToArray(json));
assertEquals("my/path/old", jsonParser.parseJSONlistToArray(json).get(0));
assertEquals("my/path/new", jsonParser.parseJSONlistToArray(json).get(1));
}
@Test
void convertJSONtoString() throws IOException {
HttpExchange httpExchangeMock = mock(HttpExchange.class);
String bodyString = "sampleRequestBody";
InputStream inputStream = new ByteArrayInputStream(bodyString.getBytes());
when(httpExchangeMock.getRequestBody()).thenReturn(inputStream);
assertEquals(bodyString, jsonParser.convertJSONtoString(httpExchangeMock));
}
}