@@ -26,15 +26,12 @@ public class SchemaProcessorTest {
26
26
@ Mocked
27
27
ExternalRefProcessor externalRefProcessor ;
28
28
29
-
30
29
@ Test
31
30
public void testProcessRefSchema_ExternalRef () throws Exception {
32
31
33
32
final String ref = "http://my.company.com/path/to/file.json#/foo/bar" ;
34
33
final String newRef = "bar" ;
35
34
36
- expectCreationOfExternalRefProcessor ();
37
-
38
35
new Expectations () {{
39
36
40
37
externalRefProcessor .processRefToExternalSchema (ref , RefFormat .URL );
@@ -54,8 +51,6 @@ public void testProcessRefSchema_ExternalRef() throws Exception {
54
51
public void testProcessRefSchema_InternalRef () throws Exception {
55
52
final String ref = "#/components/schemas/bar" ;
56
53
57
- expectCreationOfExternalRefProcessor ();
58
-
59
54
Schema refModel = new Schema ().$ref (ref );
60
55
61
56
new SchemaProcessor (cache , openAPI ).processSchema (refModel );
@@ -85,7 +80,6 @@ public void testProcessArraySchema() throws Exception {
85
80
86
81
@ Test
87
82
public void testProcessComposedSchema () throws Exception {
88
- expectCreationOfExternalRefProcessor ();
89
83
90
84
final String ref1 = "http://my.company.com/path/to/file.json#/foo/bar" ;
91
85
final String ref2 = "http://my.company.com/path/to/file.json#/this/that" ;
@@ -152,32 +146,38 @@ public void testProcessSchema() throws Exception {
152
146
153
147
@ Test
154
148
public void testProcessRefProperty_ExternalRef () throws Exception {
155
- expectCreationOfExternalRefProcessor ();
149
+
150
+ final ExternalRefProcessor [] erp = {new ExternalRefProcessor (cache , openAPI )};
151
+ new Expectations () {{
152
+ erp [0 ] = new ExternalRefProcessor (cache , openAPI );
153
+ times = 1 ;
154
+ }};
156
155
157
156
final String ref = "http://my.company.com/path/to/file.json#/foo/bar" ;
158
157
final Schema refProperty = new Schema ().$ref (ref );
159
158
160
- expectCallToExternalRefProcessor (ref , RefFormat .URL , "bar" );
159
+ new Expectations () {{
160
+ erp [0 ].processRefToExternalSchema (ref , RefFormat .URL );
161
+ times = 1 ;
162
+ result = "bar" ;
163
+ }};
161
164
162
165
new SchemaProcessor (cache , openAPI ).processSchema (refProperty );
163
166
164
167
new FullVerifications () {{
168
+ erp [0 ].processRefToExternalSchema (ref , RefFormat .URL );
169
+ times = 1 ;
165
170
}};
166
171
167
172
assertEquals (refProperty .get$ref (), "#/components/schemas/bar" );
168
173
}
169
174
170
- private void expectCallToExternalRefProcessor (final String ref , final RefFormat refFormat , final String newRef ) {
175
+ @ Test
176
+ public void testProcessRefProperty_InternalRef () throws Exception {
171
177
new Expectations () {{
172
- externalRefProcessor . processRefToExternalSchema ( ref , refFormat );
178
+ new ExternalRefProcessor ( cache , openAPI );
173
179
times = 1 ;
174
- result = newRef ;
175
180
}};
176
- }
177
-
178
- @ Test
179
- public void testProcessRefProperty_InternalRef () throws Exception {
180
- expectCreationOfExternalRefProcessor ();
181
181
182
182
final String expectedRef = "#/components/schemas/foo" ;
183
183
final Schema property = new Schema ().$ref (expectedRef );
@@ -191,18 +191,27 @@ public void testProcessRefProperty_InternalRef() throws Exception {
191
191
192
192
@ Test
193
193
public void testProcessArrayProperty_ItemsIsRefProperty () throws Exception {
194
- expectCreationOfExternalRefProcessor ();
194
+ final ExternalRefProcessor [] erp = {new ExternalRefProcessor (cache , openAPI )};
195
+ new Expectations () {{
196
+ erp [0 ] = new ExternalRefProcessor (cache , openAPI );
197
+ times = 1 ;
198
+ }};
195
199
final String ref = "http://my.company.com/path/to/file.json#/foo/bar" ;
196
200
final Schema refProperty = new Schema ().$ref (ref );
197
201
198
202
ArraySchema arrayProperty = new ArraySchema ();
199
203
arrayProperty .setItems (refProperty );
200
-
201
- expectCallToExternalRefProcessor (ref , RefFormat .URL , "bar" );
204
+ new Expectations () {{
205
+ erp [0 ].processRefToExternalSchema (ref , RefFormat .URL );
206
+ times = 1 ;
207
+ result = "bar" ;
208
+ }};
202
209
203
210
new SchemaProcessor (cache , openAPI ).processSchema (arrayProperty );
204
211
205
212
new FullVerifications () {{
213
+ erp [0 ].processRefToExternalSchema (ref , RefFormat .URL );
214
+ times = 1 ;
206
215
}};
207
216
208
217
assertEquals ((arrayProperty .getItems ()).get$ref (), "#/components/schemas/bar" );
@@ -211,28 +220,29 @@ public void testProcessArrayProperty_ItemsIsRefProperty() throws Exception {
211
220
212
221
@ Test
213
222
public void testProcessMapProperty_AdditionalPropertiesIsRefProperty () throws Exception {
214
- expectCreationOfExternalRefProcessor ();
223
+ final ExternalRefProcessor [] erp = {new ExternalRefProcessor (cache , openAPI )};
224
+ new Expectations () {{
225
+ erp [0 ] = new ExternalRefProcessor (cache , openAPI );
226
+ times = 1 ;
227
+ }};
215
228
final String ref = "http://my.company.com/path/to/file.json#/foo/bar" ;
216
229
final Schema refProperty = new Schema ().$ref (ref );
217
230
218
-
219
231
refProperty .setAdditionalProperties (refProperty );
220
232
221
- expectCallToExternalRefProcessor (ref , RefFormat .URL , "bar" );
233
+ new Expectations () {{
234
+ erp [0 ].processRefToExternalSchema (ref , RefFormat .URL );
235
+ times = 1 ;
236
+ result = "bar" ;
237
+ }};
222
238
223
239
new SchemaProcessor (cache , openAPI ).processSchema (refProperty );
224
240
225
241
new FullVerifications () {{
242
+ erp [0 ].processRefToExternalSchema (ref , RefFormat .URL );
243
+ times = 1 ;
226
244
}};
227
245
228
246
assertEquals ((((Schema )refProperty .getAdditionalProperties ()).get$ref ()), "#/components/schemas/bar" );
229
247
}
230
-
231
- private void expectCreationOfExternalRefProcessor () {
232
- new Expectations () {{
233
- new ExternalRefProcessor (cache , openAPI );
234
- times = 1 ;
235
- result = externalRefProcessor ;
236
- }};
237
- }
238
248
}
0 commit comments