Skip to content

Commit

Permalink
[*] Optimize Okhttp3 test case
Browse files Browse the repository at this point in the history
  • Loading branch information
i36lib committed Dec 13, 2024
1 parent 5b0ef82 commit 60b3196
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/test/java/io/github/artlibs/autotrace4j/At4jTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ void testHttpURLConnection() throws Exception {
void testOkHttpClientAsync() throws Exception {
// 01.Prepare
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(httpBinOrgUrl).build();
Request request = new Request.Builder().url(httpBinOrgUrl).build();
final TupleResult[] asyncTupleHolder = new TupleResult[1];
final Response[] responseHolder = new Response[1];
CountDownLatch latch = new CountDownLatch(1);
Expand All @@ -332,15 +331,18 @@ void testOkHttpClientAsync() throws Exception {
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
System.err.println(e.getMessage());
asyncTupleHolder[0] = generateResult();
System.err.println(asyncTupleHolder[0]);
System.err.println(e.getMessage());
latch.countDown();
}

@Override
public void onResponse(@NotNull Call call, @NotNull Response resp) {
asyncTupleHolder[0] = generateResult();
responseHolder[0] = resp;
System.err.println(asyncTupleHolder[0]);
System.err.println(resp);
latch.countDown();
}
});
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/io/github/artlibs/testsupport/TupleResult.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.artlibs.testsupport;

import com.alibaba.fastjson.JSON;

/**
* Tuple
*
Expand Down Expand Up @@ -72,4 +74,9 @@ public Object getValue5() {
public void setValue5(Object value5) {
this.value5 = value5;
}

@Override
public String toString() {
return JSON.toJSONString(this);
}
}

0 comments on commit 60b3196

Please sign in to comment.