12
12
13
13
import java .util .ArrayList ;
14
14
import java .util .concurrent .CountDownLatch ;
15
+ import java .util .concurrent .TimeUnit ;
15
16
16
17
import static junit .framework .TestCase .*;
17
18
@@ -73,34 +74,41 @@ public void tearDown() {
73
74
74
75
75
76
@ Test
76
- public void test_01_findAllEntries () {
77
+ public void test_01_findAllEntries () throws InterruptedException {
78
+ final CountDownLatch latch = new CountDownLatch (1 );
77
79
final Query query = stack .contentType (CONTENT_TYPE_UID ).query ();
78
80
query .find (new QueryResultsCallBack () {
79
81
@ Override
80
82
public void onCompletion (ResponseType responseType , QueryResult queryresult , Error error ) {
81
83
if (error == null ) {
82
84
entryUID = queryresult .getResultObjects ().get (15 ).getUid ();
83
85
}
86
+ latch .countDown ();
84
87
}
85
88
});
89
+ latch .await ();
86
90
}
87
91
88
92
@ Test
89
- public void test_02_only_fetch () {
93
+ public void test_02_only_fetch () throws InterruptedException {
94
+ final CountDownLatch latch = new CountDownLatch (1 );
90
95
final Entry entry = stack .contentType (CONTENT_TYPE_UID ).entry (entryUID );
91
96
entry .only (new String []{"price" });
92
97
entry .fetch (new EntryResultCallBack () {
93
98
@ Override
94
99
public void onCompletion (ResponseType responseType , Error error ) {
95
100
if (error == null ) {
96
- assertEquals (786 , entry .toJSON ().opt ("price" ));
101
+ assertEquals (89 , entry .toJSON ().opt ("price" ));
97
102
}
103
+ latch .countDown ();
98
104
}
99
105
});
106
+ latch .await ();
100
107
}
101
108
102
109
@ Test
103
- public void test_03_except_fetch () {
110
+ public void test_03_except_fetch () throws InterruptedException {
111
+ final CountDownLatch latch = new CountDownLatch (1 );
104
112
final Entry entry = stack .contentType (CONTENT_TYPE_UID ).entry (entryUID );
105
113
entry .except (new String []{"title" });
106
114
entry .fetch (new EntryResultCallBack () {
@@ -111,12 +119,15 @@ public void onCompletion(ResponseType responseType, Error error) {
111
119
} else {
112
120
Log .e (TAG , error .getErrorMessage ());
113
121
}
122
+ latch .countDown ();
114
123
}
115
124
});
125
+ latch .await ();
116
126
}
117
127
118
128
@ Test
119
- public void test_04_includeReference_fetch () {
129
+ public void test_04_includeReference_fetch () throws InterruptedException {
130
+ final CountDownLatch latch = new CountDownLatch (1 );
120
131
final Entry entry = stack .contentType (CONTENT_TYPE_UID ).entry (entryUID );
121
132
entry .includeReference ("category" );
122
133
entry .fetch (new EntryResultCallBack () {
@@ -133,14 +144,17 @@ public void onCompletion(ResponseType responseType, Error error) {
133
144
} catch (Exception e ) {
134
145
Log .e (TAG , e .getLocalizedMessage ());
135
146
}
147
+ latch .countDown ();
136
148
137
149
}
138
150
}
139
151
});
152
+ latch .await ();
140
153
}
141
154
142
155
@ Test
143
- public void test_05_includeReferenceOnly_fetch () {
156
+ public void test_05_includeReferenceOnly_fetch () throws InterruptedException {
157
+ final CountDownLatch latch = new CountDownLatch (1 );
144
158
final Entry entry = stack .contentType (CONTENT_TYPE_UID ).entry (entryUID );
145
159
ArrayList <String > strings = new ArrayList <>();
146
160
strings .add ("title" );
@@ -151,16 +165,19 @@ public void test_05_includeReferenceOnly_fetch() {
151
165
@ Override
152
166
public void onCompletion (ResponseType responseType , Error error ) {
153
167
if (error == null ) {
154
- assertEquals ("laptop " , entry .toJSON ().optString ("title" ));
168
+ assertEquals ("entry_lt8 " , entry .toJSON ().optString ("title" ));
155
169
}
170
+ latch .countDown ();
156
171
}
157
172
});
173
+ latch .await ();
158
174
159
175
}
160
176
161
177
162
178
@ Test
163
179
public void test_06_includeReferenceExcept_fetch () throws InterruptedException {
180
+ final CountDownLatch latch = new CountDownLatch (1 );
164
181
final Entry entry = stack .contentType (CONTENT_TYPE_UID ).entry (entryUID );
165
182
ArrayList <String > strings = new ArrayList <>();
166
183
strings .add ("color" );
@@ -184,6 +201,7 @@ public void onCompletion(ResponseType responseType, Error error) {
184
201
185
202
@ Test
186
203
public void test_07_getMarkdown_fetch () throws InterruptedException {
204
+ final CountDownLatch latch = new CountDownLatch (1 );
187
205
188
206
final Entry entry = stack .contentType ("user" ).entry (entryUID );
189
207
entry .fetch (new EntryResultCallBack () {
@@ -202,6 +220,7 @@ public void onCompletion(ResponseType responseType, Error error) {
202
220
203
221
@ Test
204
222
public void test_08_get () throws InterruptedException {
223
+ final CountDownLatch latch = new CountDownLatch (1 );
205
224
final Entry entry = stack .contentType ("user" ).entry (entryUID );
206
225
entry .fetch (new EntryResultCallBack () {
207
226
@ Override
@@ -219,6 +238,7 @@ public void onCompletion(ResponseType responseType, Error error) {
219
238
220
239
@ Test
221
240
public void test_09_getParam () throws InterruptedException {
241
+ final CountDownLatch latch = new CountDownLatch (1 );
222
242
final Entry entry = stack .contentType ("user" ).entry (entryUID );
223
243
entry .addParam ("include_dimensions" , "true" );
224
244
entry .fetch (new EntryResultCallBack () {
@@ -237,6 +257,7 @@ public void onCompletion(ResponseType responseType, Error error) {
237
257
238
258
@ Test
239
259
public void test_10_IncludeReferenceContentTypeUID () throws InterruptedException {
260
+ final CountDownLatch latch = new CountDownLatch (1 );
240
261
final Entry entry = stack .contentType ("user" ).entry (entryUID );
241
262
entry .includeReferenceContentTypeUID ();
242
263
entry .fetch (new EntryResultCallBack () {
@@ -266,6 +287,7 @@ public void onCompletion(ResponseType responseType, Error error) {
266
287
267
288
@ Test
268
289
public void test_11_Locale () throws InterruptedException {
290
+ final CountDownLatch latch = new CountDownLatch (1 );
269
291
final Entry entry = stack .contentType ("user" ).entry (entryUID );
270
292
entry .fetch (new EntryResultCallBack () {
271
293
@ Override
@@ -305,6 +327,7 @@ public void onCompletion(ResponseType responseType, Error error) {
305
327
306
328
@ Test
307
329
public void test_13_entry_include_embedded_items_unit_test () throws InterruptedException {
330
+ final CountDownLatch latch = new CountDownLatch (1 );
308
331
309
332
final Entry entry = stack .contentType ("user" ).entry (entryUID );
310
333
entry .includeEmbeddedItems ().fetch (new EntryResultCallBack () {
@@ -323,25 +346,31 @@ public void onCompletion(ResponseType responseType, Error error) {
323
346
}
324
347
325
348
@ Test
326
- public void VariantsTestSingleUid (){
349
+ public void VariantsTestSingleUid () throws InterruptedException {
350
+ final CountDownLatch latch = new CountDownLatch (1 );
327
351
final Entry entry = stack .contentType ("product" ).entry (variantEntryUID ).variants (variantUID );
328
352
entry .fetch (new EntryResultCallBack () {
329
353
@ Override
330
354
public void onCompletion (ResponseType responseType , Error error ) {
331
355
// assertEquals(variantUID, entry.getHeaders().get("x-cs-variant-uid"));
332
356
System .out .println (entry .toJSON ());
357
+ latch .countDown ();
333
358
}
334
359
});
360
+ latch .await ();
335
361
}
336
362
@ Test
337
- public void VariantsTestArray (){
363
+ public void VariantsTestArray () throws InterruptedException {
364
+ final CountDownLatch latch = new CountDownLatch (1 );
338
365
final Entry entry = stack .contentType ("product" ).entry (variantEntryUID ).variants (variantsUID );
339
366
entry .fetch (new EntryResultCallBack () {
340
367
@ Override
341
368
public void onCompletion (ResponseType responseType , Error error ) {
342
369
System .out .println (entry .toJSON ());
370
+ latch .countDown ();
343
371
}
344
372
});
373
+ latch .await ();
345
374
}
346
375
347
376
}
0 commit comments