Skip to content

Commit 19877c2

Browse files
committed
fix okhttp test deprecation errors
1 parent 2f013cf commit 19877c2

File tree

4 files changed

+26
-32
lines changed

4 files changed

+26
-32
lines changed

tests/src/test/java/io/jooby/FeaturedTest.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ public void multipart() {
564564
}).ready(client -> {
565565
client.post("/large", new MultipartBody.Builder()
566566
.setType(MultipartBody.FORM)
567-
.addFormDataPart("f", "19kb.txt", create(MediaType.parse("text/plain"), _19kb))
567+
.addFormDataPart("f", "19kb.txt", create(_19kb, MediaType.parse("text/plain")))
568568
.build(), rsp -> {
569569
assertEquals(_19kb, rsp.body().string());
570570
});
@@ -573,8 +573,8 @@ public void multipart() {
573573
.setType(MultipartBody.FORM)
574574
.addFormDataPart("user.name", "user")
575575
.addFormDataPart("f", "fileupload.js",
576-
create(MediaType.parse("application/javascript"),
577-
userdir("src", "test", "resources", "files", "fileupload.js").toFile()))
576+
create(userdir("src", "test", "resources", "files", "fileupload.js").toFile(),
577+
MediaType.parse("application/javascript")))
578578
.build(), rsp -> {
579579
assertEquals("fileupload.js(type=application/javascript;exists=true)",
580580
rsp.body().string());
@@ -583,10 +583,8 @@ public void multipart() {
583583
client.post("/files", new MultipartBody.Builder()
584584
.setType(MultipartBody.FORM)
585585
.addFormDataPart("user.name", "user")
586-
.addFormDataPart("f", "f1.txt",
587-
create(MediaType.parse("text/plain"), "text1"))
588-
.addFormDataPart("f", "f2.txt",
589-
create(MediaType.parse("text/plain"), "text2"))
586+
.addFormDataPart("f", "f1.txt", create("text1", MediaType.parse("text/plain")))
587+
.addFormDataPart("f", "f2.txt", create("text2", MediaType.parse("text/plain")))
590588
.build(), rsp -> {
591589
assertEquals("[f1.txt=5, f2.txt=5]", rsp.body().string());
592590
});
@@ -595,9 +593,9 @@ public void multipart() {
595593
.setType(MultipartBody.FORM)
596594
.addFormDataPart("user.name", "user")
597595
.addFormDataPart("f", "f1.txt",
598-
create(MediaType.parse("text/plain"), "text1"))
596+
create("text1", MediaType.parse("text/plain")))
599597
.addFormDataPart("f", "f2.txt",
600-
create(MediaType.parse("text/plain"), "text2"))
598+
create("text2", MediaType.parse("text/plain")))
601599
.build(), rsp -> {
602600
assertEquals("{user.name=[user], f=[f1.txt, f2.txt]}", rsp.body().string());
603601
});
@@ -606,8 +604,8 @@ public void multipart() {
606604
.setType(MultipartBody.FORM)
607605
.addFormDataPart("name", "foo_report")
608606
.addFormDataPart("filename", "fileupload.js",
609-
create(MediaType.parse("application/javascript"),
610-
userdir("src", "test", "resources", "files", "fileupload.js").toFile()))
607+
create(userdir("src", "test", "resources", "files", "fileupload.js").toFile(),
608+
MediaType.parse("application/javascript")))
611609
.build(), rsp -> {
612610
assertEquals("foo_report=true", rsp.body().string());
613611
});
@@ -616,9 +614,9 @@ public void multipart() {
616614
.setType(MultipartBody.FORM)
617615
.addFormDataPart("name", "foo_report")
618616
.addFormDataPart("filename", "f1.txt",
619-
create(MediaType.parse("text/plain"), "text1"))
617+
create("text1", MediaType.parse("text/plain")))
620618
.addFormDataPart("filename", "f2.txt",
621-
create(MediaType.parse("text/plain"), "text2"))
619+
create("text2", MediaType.parse("text/plain")))
622620
.build(), rsp -> {
623621
assertEquals("foo_report=[f1.txt, f2.txt]", rsp.body().string());
624622
});
@@ -703,16 +701,16 @@ public void parser() {
703701
app.post("/str", ctx -> ctx.body().value());
704702
}).ready((client, server) -> {
705703
client.header("Content-Type", "application/json");
706-
client.post("/map", create(json, "{\"foo\": \"bar\"}"), rsp -> {
704+
client.post("/map", create("{\"foo\": \"bar\"}", json), rsp -> {
707705
assertEquals("{\"foo\":\"bar\"}", rsp.body().string());
708706
});
709707

710708
client.header("Content-Type", "application/json");
711-
client.post("/ints", create(json, "[3, 4, 1]"), rsp -> {
709+
client.post("/ints", create("[3, 4, 1]", json), rsp -> {
712710
assertEquals("[3,4,1]", rsp.body().string());
713711
});
714712

715-
client.post("/str", create(textplain, _19kb), rsp -> {
713+
client.post("/str", create(_19kb, textplain), rsp -> {
716714
String value = rsp.body().string();
717715
assertEquals(_19kb, value,
718716
server.getClass().getSimpleName() + " expected: " + _19kb.length() + ", got: " + value
@@ -1236,21 +1234,21 @@ public void maxRequestSize() {
12361234
app.get("/request-size", ctx -> ctx.body().value());
12371235
}).ready((client, server) -> {
12381236
// Exceeds
1239-
client.post("/request-size", RequestBody.create(MediaType.get("text/plain"), _19kb), rsp -> {
1237+
client.post("/request-size", RequestBody.create(_19kb, MediaType.get("text/plain")), rsp -> {
12401238
assertEquals(413, rsp.code(), server.getClass().getSimpleName());
12411239
});
12421240
// Chunk by chunk
1243-
client.post("/request-size", RequestBody.create(MediaType.get("text/plain"), _16kb), rsp -> {
1241+
client.post("/request-size", RequestBody.create(_16kb, MediaType.get("text/plain")), rsp -> {
12441242
assertEquals(200, rsp.code());
12451243
assertEquals(_16kb, rsp.body().string(), server.getClass().getSimpleName());
12461244
});
12471245
// Single read
1248-
client.post("/request-size", RequestBody.create(MediaType.get("text/plain"), _8kb), rsp -> {
1246+
client.post("/request-size", RequestBody.create(_8kb, MediaType.get("text/plain")), rsp -> {
12491247
assertEquals(200, rsp.code());
12501248
assertEquals(_8kb, rsp.body().string(), server.getClass().getSimpleName());
12511249
});
12521250
// Empty
1253-
client.post("/request-size", RequestBody.create(MediaType.get("text/plain"), ""), rsp -> {
1251+
client.post("/request-size", RequestBody.create("", MediaType.get("text/plain")), rsp -> {
12541252
assertEquals(200, rsp.code());
12551253
assertEquals("", rsp.body().string(), server.getClass().getSimpleName());
12561254
});

tests/src/test/java/io/jooby/MvcTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,31 +312,31 @@ public void mvcBody() {
312312

313313
}).ready(client -> {
314314
client.header("Content-Type", "text/plain");
315-
client.post("/body/str", create(MediaType.get("text/plain"), "..."), rsp -> {
315+
client.post("/body/str", create("...", MediaType.get("text/plain")), rsp -> {
316316
assertEquals("...", rsp.body().string());
317317
});
318318
client.header("Content-Type", "text/plain");
319-
client.post("/body/int", create(MediaType.get("text/plain"), "8"), rsp -> {
319+
client.post("/body/int", create("8", MediaType.get("text/plain")), rsp -> {
320320
assertEquals("8", rsp.body().string());
321321
});
322-
client.post("/body/int", create(MediaType.get("text/plain"), "8x"), rsp -> {
322+
client.post("/body/int", create("8x", MediaType.get("text/plain")), rsp -> {
323323
assertEquals("Unable to provision parameter: 'body: int'", rsp.body().string());
324324
});
325325
client.header("Content-Type", "application/json");
326-
client.post("/body/json", create(MediaType.get("application/json"), "{\"foo\"= \"bar\"}"),
326+
client.post("/body/json", create("{\"foo\"= \"bar\"}", MediaType.get("application/json")),
327327
rsp -> {
328328
assertEquals(
329329
"Unable to provision parameter: 'body: java.util.Map<java.lang.String, java.lang.Object>'",
330330
rsp.body().string());
331331
});
332332
client.header("Content-Type", "application/json");
333-
client.post("/body/json", create(MediaType.get("application/json"), "{\"foo\": \"bar\"}"),
333+
client.post("/body/json", create("{\"foo\": \"bar\"}", MediaType.get("application/json")),
334334
rsp -> {
335335
assertEquals("{foo=bar}null", rsp.body().string());
336336
});
337337
client.header("Content-Type", "application/json");
338338
client.post("/body/json?type=x",
339-
create(MediaType.get("application/json"), "{\"foo\": \"bar\"}"), rsp -> {
339+
create("{\"foo\": \"bar\"}", MediaType.get("application/json")), rsp -> {
340340
assertEquals("{foo=bar}x", rsp.body().string());
341341
});
342342
});

tests/src/test/java/io/jooby/WebClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void execute(SneakyThrows.Consumer<Response> callback) {
3939
}
4040
}
4141

42-
private static RequestBody EMPTY_BODY = RequestBody.create(null, new byte[0]);
42+
private static RequestBody EMPTY_BODY = RequestBody.create(new byte[0], null);
4343
private final int port;
4444
private OkHttpClient client;
4545
private Map<String, String> headers;

tests/src/test/kotlin/io/jooby/FeaturedKotlinTest.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@ class FeaturedKotlinTest {
1212
@Test
1313
fun explicitContext() {
1414
JoobyRunner { app ->
15-
app.get("/") { ctx ->
15+
app.get("/") {
1616
"Hello World!"
1717
}
18-
19-
app.error { ctx, cause, statusCode ->
20-
21-
}
2218
}.ready { client ->
2319
client.get("/") { rsp ->
2420
assertEquals("Hello World!", rsp.body!!.string())

0 commit comments

Comments
 (0)