Skip to content

Instantly share code, notes, and snippets.

@IvanShafran
Created December 27, 2019 12:48
Show Gist options
  • Save IvanShafran/fbf1862af945f70bddf998038cf15b25 to your computer and use it in GitHub Desktop.
Save IvanShafran/fbf1862af945f70bddf998038cf15b25 to your computer and use it in GitHub Desktop.
package com.abbyy.rtr.ui.sample.imagecapture.flexicapture;
import org.junit.Rule;
import org.junit.Test;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
public class OkHttpBug {
@Rule public final MockWebServer server = new MockWebServer();
@Test
public void test() throws Exception
{
server.enqueue( new MockResponse()
.addHeader( "Content-Type: text/plain" )
.setBody( "abc" ) );
Request request = new Request.Builder()
.url( server.url( "https://google.com`" ) )
.header( "User-Agent", "Test Case" )
.build();
OkHttpClient client = new OkHttpClient();
Call call = client.newCall( request );
CountDownLatch countDownLatch = new CountDownLatch( 1 );
call.enqueue( new Callback() {
@Override
public void onFailure( Call call, IOException e )
{
// Never called
countDownLatch.countDown();
}
@Override
public void onResponse( Call call, Response response ) throws IOException
{
// Never called
countDownLatch.countDown();
}
} );
// RuntimeException(URISyntaxException) is thrown on WorkerThread. Android app is crashed.
// Waiting forever...
countDownLatch.await();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment