Skip to content

Commit f6ebbd1

Browse files
committed
Create easy to read expected Percl Json for testing
1 parent c07ad0c commit f6ebbd1

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ dependencies {
119119
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
120120
testImplementation 'junit:junit:4.13.2'
121121
testImplementation 'org.mockito:mockito-core:3.12.4'
122+
implementation 'org.json:json:20171018'
122123
}
123124

124125
javadoc {

src/test/java/com/github/freeclimbapi/manual/PerclScriptBuildTest.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,47 @@
33
import com.github.freeclimbapi.enums.*;
44
import com.github.freeclimbapi.models.*;
55
import java.util.*;
6+
import org.json.JSONArray;
7+
import org.json.JSONObject;
68
import org.junit.Assert;
79
import org.junit.Test;
810

911
public class PerclScriptBuildTest {
1012

1113
private final PerclScript instance = new PerclScript();
1214

13-
public String expectedPerclJson =
14-
"[{\"Pause\":{}},{\"SendDigits\":{}},{\"Pause\":{}},{\"GetDigits\":{\"prompts\":[{\"Play\":"
15-
+ "{\"file\":\"https://123.com/press_any_key.wav\"}},{\"Pause\":{}},{\"Play\":{\"file\":\"https://123.com/press_any_key.wav\"}}"
16-
+ ",{\"Pause\":{}},{\"Play\":{\"file\":\"https://123.com/press_any_key.wav\"}},{\"Pause\":{}}]}}]";
15+
JSONObject getPerclCommand(String command, JSONObject value) {
16+
JSONObject perclCommand = new JSONObject();
17+
perclCommand.put(command, value);
18+
return perclCommand;
19+
}
20+
21+
JSONArray createExpectedPercl() {
22+
JSONArray result = new JSONArray();
23+
result.put(getPerclCommand("Pause", new JSONObject()));
24+
result.put(getPerclCommand("SendDigits", new JSONObject()));
25+
result.put(getPerclCommand("Pause", new JSONObject()));
26+
JSONObject getDigits = new JSONObject();
27+
JSONArray getDigitPrompts = new JSONArray();
28+
JSONObject playValue = new JSONObject();
29+
playValue.put("file", "https://123.com/press_any_key.wav");
30+
getDigitPrompts.put(getPerclCommand("Play", playValue));
31+
getDigitPrompts.put(getPerclCommand("Pause", new JSONObject()));
32+
getDigitPrompts.put(getPerclCommand("Play", playValue));
33+
getDigitPrompts.put(getPerclCommand("Pause", new JSONObject()));
34+
getDigitPrompts.put(getPerclCommand("Play", playValue));
35+
getDigitPrompts.put(getPerclCommand("Pause", new JSONObject()));
36+
getDigits.put("prompts", getDigitPrompts);
37+
result.put(getPerclCommand("GetDigits", getDigits));
38+
return result;
39+
}
40+
41+
public JSONArray expectedPerclJsonArray = createExpectedPercl();
42+
43+
public String expectedPerclJson = expectedPerclJsonArray.toString();
1744

1845
@Test
1946
public void buildArrayListToJsonTest() throws Exception {
20-
JSON jsonWriter = new JSON();
2147
Pause pause = new Pause();
2248
SendDigits sendDigits = new SendDigits();
2349
GetDigits digits = new GetDigits();
@@ -45,7 +71,6 @@ public void buildArrayListToJsonTest() throws Exception {
4571

4672
@Test
4773
public void buildLinkedListToJsonTest() throws Exception {
48-
JSON jsonWriter = new JSON();
4974
Pause pause = new Pause();
5075
SendDigits sendDigits = new SendDigits();
5176
GetDigits digits = new GetDigits();

0 commit comments

Comments
 (0)