Skip to content

Commit 0f4f45d

Browse files
committed
Fix outputs
1 parent 522904c commit 0f4f45d

File tree

1 file changed

+36
-52
lines changed

1 file changed

+36
-52
lines changed

tests/languages/android/Tests.java

Lines changed: 36 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -95,68 +95,52 @@ public void test() throws IOException {
9595
return null;
9696
});
9797

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+
}));
127116

128117
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));
131119
} catch (Exception ex) {
132120
writeToFile(ex.toString());
133121
}
134122

135123
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));
138125
} catch (Exception ex) {
139126
writeToFile(ex.toString());
140127
}
141128

142129
try {
143130
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));
146132
} catch (Exception ex) {
147133
writeToFile(ex.toString());
148134
}
149135

150136
try {
151137
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));
154139
} catch (Exception ex) {
155140
writeToFile(ex.toString());
156141
}
157142

158-
mock = general.enum(MockType.FIRST);
159-
writeToFile(mock.getResult());
143+
general.enum(MockType.FIRST, new CoroutineCallback<>(this::writeMockResult));
160144

161145
try {
162146
general.error400();
@@ -176,18 +160,8 @@ public void test() throws IOException {
176160
writeToFile(e.getMessage());
177161
}
178162

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-
188163
general.empty();
189164

190-
// Query helper tests
191165
writeToFile(Query.Companion.equal("released", List.of(true)).toString());
192166
writeToFile(Query.Companion.equal("title", List.of("Spiderman", "Dr. Strange")).toString());
193167
writeToFile(Query.Companion.notEqual("title", "Spiderman").toString());
@@ -227,13 +201,23 @@ public void test() throws IOException {
227201
writeToFile(ID.Companion.unique().toString());
228202
writeToFile(ID.Companion.custom("custom_id").toString());
229203

230-
mock = general.headers();
231-
writeToFile(mock.getResult());
204+
general.headers(new CoroutineCallback<>(this::writeMockResult));
232205

233-
return null;
206+
delay(5000, continuation);
207+
writeToFile(realtimeResponse[0]);
208+
209+
return Unit.INSTANCE;
234210
});
235211
}
236212

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+
237221
private void writeToFile(String string) {
238222
String text = (string != null ? string : "") + "\n";
239223
try {

0 commit comments

Comments
 (0)