title: How to wait for the result on a Okhttp call to use it on a test?
body: <p>I've created a method to check if my app is able to connect to my server using OkHttp.</p>
  
  <p>This is my test class:</p>
  
  <pre><code>public class NetworkTest {
  
  static boolean resultWeb = false;
  
  public static boolean pingTestWeb() {
  
      OkHttpClient client = new OkHttpClient();
  
      Request request = new Request.Builder()
              .url("http://www.google.com")//My server address will go here
              .build();
  
      client.newCall(request).enqueue(new Callback() {
  
          @Override
          public void onFailure(Request request, IOException e) {
              resultWeb = false;
              Log.i("Error","Failed to connect: "+e.getMessage());
          }
  
          @Override
          public void onResponse(Response response) throws IOException {
  
              Log.i("Success","Success: "+response.code());
              if (response.code() == 200) {
                  resulWeb = true;
              }
          }
      });
  
      return resultWeb;
  }
  </code></pre>
  
  <p>And here is where I'm making the test on my activity on OnCreate():</p>
  
  <pre><code>if (NetworkTest.pingTestWeb()) {
  
          // Do something if true...
  
      } else {
  
          // Do something if false, like showing an AlertDialog...
      }
  </code></pre>
  
  <p>The question is, my pingTestWeb have the default Timeout time of 10000ms, how do I make the activity create the AlertDialog only if the pingTestWeb is false? Because it isn't waiting for the response.</p>