PassRequest { @SuppressLint("NewApi") public void execute(@NonNull Callback callback) { execute(callback, null); } PassRequest(@NonNull Builder builder, @NonNull RequestFactory requestFactory, @NonNull Executor requestExecutor);   PassRequest(@NonNull Builder builder); @NonNull static Builder newBuilder(); @SuppressLint("NewApi") void execute(@NonNull Callback callback); @SuppressLint("NewApi") void execute(@NonNull Callback callback, @Nullable Looper looper); void cancel(); @NonNull @Override String toString();  }
@Test public void testExecute() throws Exception { final String requestJson = "{\n" + " \"headers\":{\n" + " \"expirationDate\":{\n" + " \"value\":\"2014-08-20T9:41-08:00\"\n" + " },\n" + " \"barcodeAltText\":{\n" + " \"value\":\"abc1234567890\",\n" + " \"label\":\"label\"\n" + " },\n" + " \"barcode_value\":{\n" + " \"value\":\"abc1234567890\",\n" + " \"label\":\"label\"\n" + " }\n" + " },\n" + " \"publicURL\" : {\n" + " \"type\" : \"multiple\"\n" + " },\n" + " \"tag\": \"Text Tag\",\n" + " \"externalId\": \"id123\",\n" + " \"fields\":{\n" + " \"Text\":{\n" + " \"value\":\"Text Value\",\n" + " \"label\":\"Text Label\"\n" + " }\n" + " }\n" + "}"; String responseJson = "{\n" + " \"createdAt\":\"2016-06-09T18:07:42Z\",\n" + " \"publicUrl\":{\n" + " \"path\":\"https:\\/\\/goo.gl\\/app\\/pay?link=https:\\/\\/www.android.com\\/payapp\\/savetoandroidpay\\/555\",\n" + " \"type\":\"Single\"\n" + " },\n" + " \"id\":\"5\",\n" + " \"status\":\"not_been_installed\"\n" + "}"; final TestPassRequest testRequest = new TestPassRequest(requestJson); testRequest.response = new Response.Builder<Void>(HttpURLConnection.HTTP_OK) .setResponseBody(responseJson) .build(); RequestFactory requestFactory = Mockito.mock(RequestFactory.class); when(requestFactory.createRequest(anyString(), any(URL.class))).thenReturn(testRequest); Field field = Field.newBuilder() .setName("Text") .setValue("Text Value") .setLabel("Text Label") .build(); PassRequest.Builder passRequestBuilder = PassRequest.newBuilder() .setAuth("test_user_name", "test_api_key") .setTemplateId("test_template_id") .setExpirationDate("2014-08-20T9:41-08:00", null) .setBarcodeAltText("abc1234567890", "label") .setBarcodeValue("abc1234567890", "label") .setTag("Text Tag") .setExternalId("id123") .addField(field); Executor executor = new Executor() { @Override public void execute(Runnable command) { command.run(); } }; final CountDownLatch latch = new CountDownLatch(1); Callback callback = new Callback() { @Override public void onResult(@NonNull Pass pass) { assertEquals("5", pass.getId()); assertEquals(Uri.parse("https: latch.countDown(); } @Override public void onError(int errorCode) { throw new RuntimeException(); } }; PassRequest passRequest = new PassRequest(passRequestBuilder, requestFactory, executor); passRequest.execute(callback, null); latch.await(); }