11package org .example ;
22
3+ import org .junit .jupiter .api .Disabled ;
34import org .junit .jupiter .api .Test ;
45import retrofit2 .Call ;
6+ import retrofit2 .Callback ;
57import retrofit2 .Response ;
68import retrofit2 .Retrofit ;
79import retrofit2 .converter .gson .GsonConverterFactory ;
1214
1315public class GitHubServiceTest {
1416
17+ @ Disabled
1518 @ Test
16- public void test () throws IOException {
19+ void test () throws IOException {
1720
1821 Retrofit retrofit = new Retrofit .Builder ()
1922 .baseUrl ("https://api.github.com/" )
@@ -23,16 +26,25 @@ public void test() throws IOException {
2326
2427 GitHubService service = retrofit .create (GitHubService .class );
2528 final Call <List <Repo >> call = service .listRepos ("octocat" );
26- final Response <List <Repo >> res = call .execute ();
27- final List <Repo > body = res .body ();
28-
29- System .out .println ("done " +body );
29+ call .enqueue (new Callback <>() {
30+ @ Override
31+ public void onResponse (Call <List <Repo >> call , Response <List <Repo >> response ) {
32+ System .out .println ("onResponse repo count: " + response .body ().size ());
33+ }
34+
35+ @ Override
36+ public void onFailure (Call <List <Repo >> call , Throwable throwable ) {
37+ System .out .println ("onFailure: " + throwable );
38+ }
39+ });
40+ // final Response<List<Repo>> res = call.execute();
41+ // final List<Repo> body = res.body();
42+ // System.out.println("done count: "+body.size());
3043
3144 final Call <String > call2 = service .list2 ("octocat" );
3245 final Response <String > res2 = call2 .execute ();
3346 final String body2 = res2 .body ();
3447
35- System .out .println ("done " +body2 );
36-
48+ System .out .println ("done length: " + body2 .length ());
3749 }
3850}
0 commit comments