Skip to content

Commit 0de9b59

Browse files
add tests for JsonToStringStyler
1 parent 5a82224 commit 0de9b59

File tree

1 file changed

+196
-0
lines changed

1 file changed

+196
-0
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
/*
2+
* Copyright 2020 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.utplsql.sqldev.test;
17+
18+
import java.util.Arrays;
19+
20+
import org.junit.Assert;
21+
import org.junit.Test;
22+
import org.utplsql.sqldev.model.runner.Run;
23+
import org.utplsql.sqldev.model.ut.OutputLines;
24+
25+
public class JsonToStringStylerTest {
26+
27+
@Test
28+
public void outputLinesWithTreeLines() {
29+
final OutputLines o = new OutputLines();
30+
o.setLines(new String[] { "line \"1\"", "line2", "line3" });
31+
o.setNumlines(3);
32+
33+
final String actual = o.toString();
34+
35+
final StringBuilder sb = new StringBuilder();
36+
sb.append("{\n");
37+
sb.append(" \"className\": \"OutputLines\",\n");
38+
sb.append(" \"lines\": [\n");
39+
sb.append(" \"line \\\"1\\\"\",\n");
40+
sb.append(" \"line2\",\n");
41+
sb.append(" \"line3\"\n");
42+
sb.append(" ],\n");
43+
sb.append(" \"numlines\": 3\n");
44+
sb.append("}");
45+
Assert.assertEquals(sb.toString(), actual);
46+
}
47+
48+
@Test
49+
public void outputLinesWithoutLines() {
50+
final OutputLines o = new OutputLines();
51+
o.setLines(new String[] {});
52+
o.setNumlines(0);
53+
54+
final String actual = o.toString();
55+
56+
final StringBuilder sb = new StringBuilder();
57+
sb.append("{\n");
58+
sb.append(" \"className\": \"OutputLines\",\n");
59+
sb.append(" \"lines\": [],\n");
60+
sb.append(" \"numlines\": 0\n");
61+
sb.append("}");
62+
Assert.assertEquals(sb.toString(), actual);
63+
}
64+
65+
@Test
66+
public void emptyRun() {
67+
final Run r = new Run("1", "MyConnection", Arrays.asList());
68+
69+
final String actual = r.toString();
70+
71+
final StringBuilder sb = new StringBuilder();
72+
sb.append("{\n");
73+
sb.append(" \"className\": \"Run\",\n");
74+
sb.append(" \"reporterId\": \"1\",\n");
75+
sb.append(" \"connectionName\": \"MyConnection\",\n");
76+
sb.append(" \"pathList\": [],\n");
77+
sb.append(" \"currentTestNumber\": null,\n");
78+
sb.append(" \"currentTest\": null,\n");
79+
sb.append(" \"totalNumberOfTests\": null,\n");
80+
sb.append(" \"startTime\": null,\n");
81+
sb.append(" \"endTime\": null,\n");
82+
sb.append(" \"executionTime\": null,\n");
83+
sb.append(" \"counter\": {\n");
84+
sb.append(" \"className\": \"Counter\",\n");
85+
sb.append(" \"disabled\": null,\n");
86+
sb.append(" \"success\": null,\n");
87+
sb.append(" \"failure\": null,\n");
88+
sb.append(" \"error\": null,\n");
89+
sb.append(" \"warning\": null\n");
90+
sb.append(" },\n");
91+
sb.append(" \"infoCount\": null,\n");
92+
sb.append(" \"errorStack\": null,\n");
93+
sb.append(" \"serverOutput\": null,\n");
94+
sb.append(" \"tests\": [],\n");
95+
sb.append(" \"status\": null,\n");
96+
sb.append(" \"start\": null,\n");
97+
sb.append(" \"endTime\": null,\n");
98+
sb.append(" \"totalNumberOfCompletedTests\": -1\n");
99+
sb.append("}");
100+
Assert.assertEquals(sb.toString(), actual.toString());
101+
}
102+
103+
104+
@Test
105+
public void runWithTests() {
106+
final Run r = new Run("1", "MyConnection", Arrays.asList());
107+
final org.utplsql.sqldev.model.runner.Test t1 = new org.utplsql.sqldev.model.runner.Test();
108+
t1.setId("1");
109+
t1.setName("Test One");
110+
r.getTests().put(t1.getId(), t1);
111+
final org.utplsql.sqldev.model.runner.Test t2 = new org.utplsql.sqldev.model.runner.Test();
112+
t2.setId("2");
113+
t2.setName("Test Two");
114+
r.getTests().put(t2.getId(), t2);
115+
116+
final String actual = r.toString();
117+
118+
final StringBuilder sb = new StringBuilder();
119+
sb.append("{\n");
120+
sb.append(" \"className\": \"Run\",\n");
121+
sb.append(" \"reporterId\": \"1\",\n");
122+
sb.append(" \"connectionName\": \"MyConnection\",\n");
123+
sb.append(" \"pathList\": [],\n");
124+
sb.append(" \"currentTestNumber\": null,\n");
125+
sb.append(" \"currentTest\": null,\n");
126+
sb.append(" \"totalNumberOfTests\": null,\n");
127+
sb.append(" \"startTime\": null,\n");
128+
sb.append(" \"endTime\": null,\n");
129+
sb.append(" \"executionTime\": null,\n");
130+
sb.append(" \"counter\": {\n");
131+
sb.append(" \"className\": \"Counter\",\n");
132+
sb.append(" \"disabled\": null,\n");
133+
sb.append(" \"success\": null,\n");
134+
sb.append(" \"failure\": null,\n");
135+
sb.append(" \"error\": null,\n");
136+
sb.append(" \"warning\": null\n");
137+
sb.append(" },\n");
138+
sb.append(" \"infoCount\": null,\n");
139+
sb.append(" \"errorStack\": null,\n");
140+
sb.append(" \"serverOutput\": null,\n");
141+
sb.append(" \"tests\": [\n");
142+
sb.append(" {\n");
143+
sb.append(" \"className\": \"Test\",\n");
144+
sb.append(" \"id\": \"1\",\n");
145+
sb.append(" \"startTime\": null,\n");
146+
sb.append(" \"endTime\": null,\n");
147+
sb.append(" \"executionTime\": null,\n");
148+
sb.append(" \"counter\": null,\n");
149+
sb.append(" \"errorStack\": null,\n");
150+
sb.append(" \"serverOutput\": null,\n");
151+
sb.append(" \"warnings\": null,\n");
152+
sb.append(" \"executableType\": null,\n");
153+
sb.append(" \"ownerName\": null,\n");
154+
sb.append(" \"objectName\": null,\n");
155+
sb.append(" \"procedureName\": null,\n");
156+
sb.append(" \"disabled\": null,\n");
157+
sb.append(" \"name\": \"Test One\",\n");
158+
sb.append(" \"description\": null,\n");
159+
sb.append(" \"testNumber\": null,\n");
160+
sb.append(" \"failedExpectations\": null,\n");
161+
sb.append(" \"statusIcon\": null,\n");
162+
sb.append(" \"warningIcon\": null,\n");
163+
sb.append(" \"infoIcon\": null\n");
164+
sb.append(" },\n");
165+
sb.append(" {\n");
166+
sb.append(" \"className\": \"Test\",\n");
167+
sb.append(" \"id\": \"2\",\n");
168+
sb.append(" \"startTime\": null,\n");
169+
sb.append(" \"endTime\": null,\n");
170+
sb.append(" \"executionTime\": null,\n");
171+
sb.append(" \"counter\": null,\n");
172+
sb.append(" \"errorStack\": null,\n");
173+
sb.append(" \"serverOutput\": null,\n");
174+
sb.append(" \"warnings\": null,\n");
175+
sb.append(" \"executableType\": null,\n");
176+
sb.append(" \"ownerName\": null,\n");
177+
sb.append(" \"objectName\": null,\n");
178+
sb.append(" \"procedureName\": null,\n");
179+
sb.append(" \"disabled\": null,\n");
180+
sb.append(" \"name\": \"Test Two\",\n");
181+
sb.append(" \"description\": null,\n");
182+
sb.append(" \"testNumber\": null,\n");
183+
sb.append(" \"failedExpectations\": null,\n");
184+
sb.append(" \"statusIcon\": null,\n");
185+
sb.append(" \"warningIcon\": null,\n");
186+
sb.append(" \"infoIcon\": null\n");
187+
sb.append(" }\n");
188+
sb.append(" ],\n");
189+
sb.append(" \"status\": null,\n");
190+
sb.append(" \"start\": null,\n");
191+
sb.append(" \"endTime\": null,\n");
192+
sb.append(" \"totalNumberOfCompletedTests\": -1\n");
193+
sb.append("}");
194+
Assert.assertEquals(sb.toString(), actual.toString());
195+
}
196+
}

0 commit comments

Comments
 (0)