@@ -95,68 +95,52 @@ public void test() throws IOException {
95
95
return null ;
96
96
});
97
97
98
- runBlocking (new TestCoroutineScope (), () -> {
99
- Mock mock ;
100
- // Foo Tests
101
- mock = foo .get ("string" , 123 , List .of ("string in array" ));
102
- writeToFile (mock .getResult ());
103
- mock = foo .post ("string" , 123 , List .of ("string in array" ));
104
- writeToFile (mock .getResult ());
105
- mock = foo .put ("string" , 123 , List .of ("string in array" ));
106
- writeToFile (mock .getResult ());
107
- mock = foo .patch ("string" , 123 , List .of ("string in array" ));
108
- writeToFile (mock .getResult ());
109
- mock = foo .delete ("string" , 123 , List .of ("string in array" ));
110
- writeToFile (mock .getResult ());
111
-
112
- // Bar Tests
113
- mock = bar .get ("string" , 123 , List .of ("string in array" ));
114
- writeToFile (mock .getResult ());
115
- mock = bar .post ("string" , 123 , List .of ("string in array" ));
116
- writeToFile (mock .getResult ());
117
- mock = bar .put ("string" , 123 , List .of ("string in array" ));
118
- writeToFile (mock .getResult ());
119
- mock = bar .patch ("string" , 123 , List .of ("string in array" ));
120
- writeToFile (mock .getResult ());
121
- mock = bar .delete ("string" , 123 , List .of ("string in array" ));
122
- writeToFile (mock .getResult ());
123
-
124
- // General Tests
125
- Object result = general .redirect ();
126
- writeToFile ((String ) ((Map <String , Object >) result ).get ("result" ));
98
+ runBlocking (Dispatchers .getDefault (), (Continuation <Unit >) continuation -> {
99
+ foo .get ("string" , 123 , List .of ("string in array" ), new CoroutineCallback <>(this ::writeMockResult ));
100
+ foo .post ("string" , 123 , List .of ("string in array" ), new CoroutineCallback <>(this ::writeMockResult ));
101
+ foo .put ("string" , 123 , List .of ("string in array" ), new CoroutineCallback <>(this ::writeMockResult ));
102
+ foo .patch ("string" , 123 , List .of ("string in array" ), new CoroutineCallback <>(this ::writeMockResult ));
103
+ foo .delete ("string" , 123 , List .of ("string in array" ), new CoroutineCallback <>(this ::writeMockResult ));
104
+
105
+ bar .get ("string" , 123 , List .of ("string in array" ), new CoroutineCallback <>(this ::writeMockResult ));
106
+ bar .post ("string" , 123 , List .of ("string in array" ), new CoroutineCallback <>(this ::writeMockResult ));
107
+ bar .put ("string" , 123 , List .of ("string in array" ), new CoroutineCallback <>(this ::writeMockResult ));
108
+ bar .patch ("string" , 123 , List .of ("string in array" ), new CoroutineCallback <>(this ::writeMockResult ));
109
+ bar .delete ("string" , 123 , List .of ("string in array" ), new CoroutineCallback <>(this ::writeMockResult ));
110
+
111
+ general .redirect (new CoroutineCallback <>((result , error ) -> {
112
+ if (result != null ) {
113
+ writeToFile (((Map <String , Object >) result ).get ("result" ).toString ());
114
+ }
115
+ }));
127
116
128
117
try {
129
- mock = general .upload ("string" , 123 , List .of ("string in array" ), InputFile .fromPath ("../../../resources/file.png" ));
130
- writeToFile (mock .getResult ());
118
+ general .upload ("string" , 123 , List .of ("string in array" ), InputFile .fromPath ("../../../resources/file.png" ), new CoroutineCallback <>(this ::writeMockResult ));
131
119
} catch (Exception ex ) {
132
120
writeToFile (ex .toString ());
133
121
}
134
122
135
123
try {
136
- mock = general .upload ("string" , 123 , List .of ("string in array" ), InputFile .fromPath ("../../../resources/large_file.mp4" ));
137
- writeToFile (mock .getResult ());
124
+ general .upload ("string" , 123 , List .of ("string in array" ), InputFile .fromPath ("../../../resources/large_file.mp4" ), new CoroutineCallback <>(this ::writeMockResult ));
138
125
} catch (Exception ex ) {
139
126
writeToFile (ex .toString ());
140
127
}
141
128
142
129
try {
143
130
byte [] bytes = Files .readAllBytes (Paths .get ("../../../resources/file.png" ));
144
- mock = general .upload ("string" , 123 , List .of ("string in array" ), InputFile .fromBytes (bytes , "file.png" , "image/png" ));
145
- writeToFile (mock .getResult ());
131
+ general .upload ("string" , 123 , List .of ("string in array" ), InputFile .fromBytes (bytes , "file.png" , "image/png" ), new CoroutineCallback <>(this ::writeMockResult ));
146
132
} catch (Exception ex ) {
147
133
writeToFile (ex .toString ());
148
134
}
149
135
150
136
try {
151
137
byte [] bytes = Files .readAllBytes (Paths .get ("../../../resources/large_file.mp4" ));
152
- mock = general .upload ("string" , 123 , List .of ("string in array" ), InputFile .fromBytes (bytes , "large_file.mp4" , "video/mp4" ));
153
- writeToFile (mock .getResult ());
138
+ general .upload ("string" , 123 , List .of ("string in array" ), InputFile .fromBytes (bytes , "large_file.mp4" , "video/mp4" ), new CoroutineCallback <>(this ::writeMockResult ));
154
139
} catch (Exception ex ) {
155
140
writeToFile (ex .toString ());
156
141
}
157
142
158
- mock = general .enum (MockType .FIRST );
159
- writeToFile (mock .getResult ());
143
+ general .enum (MockType .FIRST , new CoroutineCallback <>(this ::writeMockResult ));
160
144
161
145
try {
162
146
general .error400 ();
@@ -176,18 +160,8 @@ public void test() throws IOException {
176
160
writeToFile (e .getMessage ());
177
161
}
178
162
179
- delay (5000 );
180
- writeToFile (realtimeResponse );
181
-
182
- // mock = general.setCookie();
183
- // writeToFile(mock.getResult());
184
-
185
- // mock = general.getCookie();
186
- // writeToFile(mock.getResult());
187
-
188
163
general .empty ();
189
164
190
- // Query helper tests
191
165
writeToFile (Query .Companion .equal ("released" , List .of (true )).toString ());
192
166
writeToFile (Query .Companion .equal ("title" , List .of ("Spiderman" , "Dr. Strange" )).toString ());
193
167
writeToFile (Query .Companion .notEqual ("title" , "Spiderman" ).toString ());
@@ -227,13 +201,23 @@ public void test() throws IOException {
227
201
writeToFile (ID .Companion .unique ().toString ());
228
202
writeToFile (ID .Companion .custom ("custom_id" ).toString ());
229
203
230
- mock = general .headers ();
231
- writeToFile (mock .getResult ());
204
+ general .headers (new CoroutineCallback <>(this ::writeMockResult ));
232
205
233
- return null ;
206
+ delay (5000 , continuation );
207
+ writeToFile (realtimeResponse [0 ]);
208
+
209
+ return Unit .INSTANCE ;
234
210
});
235
211
}
236
212
213
+ private void writeMockResult (Mock result , Throwable error ) {
214
+ if (result != null ) {
215
+ writeToFile (result .getResult ());
216
+ } else {
217
+ writeToFile (error .toString ());
218
+ }
219
+ }
220
+
237
221
private void writeToFile (String string ) {
238
222
String text = (string != null ? string : "" ) + "\n " ;
239
223
try {
0 commit comments