GooglePlayCallbackExtractor { public Pair<JobCallback, Bundle> extractCallback(@Nullable Bundle data) { if (data == null) { Log.e(TAG, ERROR_NULL_CALLBACK); return null; } return extractWrappedBinderFromParcel(data); }  Pair<JobCallback, Bundle> extractCallback(@Nullable Bundle data);  }
@Test public void testExtractCallback_nullBundle() { assertNull(extractor.extractCallback(null)); }
@Test public void testExtractCallback_nullParcelable() { Bundle emptyBundle = new Bundle(); assertNull(extractCallback(emptyBundle)); }
@Test public void testExtractCallback_badParcelable() { Bundle misconfiguredBundle = new Bundle(); misconfiguredBundle.putParcelable("callback", new BadParcelable(1)); assertNull(extractCallback(misconfiguredBundle)); }
@Test public void testExtractCallback_goodParcelable() { InspectableBinder binder = new InspectableBinder(); Bundle validBundle = new Bundle(); validBundle.putParcelable("callback", binder.toPendingCallback()); Pair<JobCallback, Bundle> extraction = extractCallback(validBundle); assertNotNull(extraction); assertEquals( "should have stripped the 'callback' entry from the extracted bundle", 0, extraction.second.keySet().size()); extraction.first.jobFinished(JobService.RESULT_SUCCESS); TransactionArguments args = binder.getArguments().get(0); assertEquals("transaction code", IBinder.FIRST_CALL_TRANSACTION + 1, args.code); args.data.readInt(); assertEquals("com.google.android.gms.gcm.INetworkTaskCallback", args.data.readString()); assertEquals("result", JobService.RESULT_SUCCESS, args.data.readInt()); }
@Test public void testExtractCallback_extraMapValues() { Bundle validBundle = new Bundle(); validBundle.putString("foo", "bar"); validBundle.putInt("bar", 3); validBundle.putParcelable("parcelable", new Bundle()); validBundle.putParcelable("callback", new InspectableBinder().toPendingCallback()); Pair<JobCallback, Bundle> extraction = extractCallback(validBundle); assertNotNull(extraction); assertEquals( "should have stripped the 'callback' entry from the extracted bundle", 3, extraction.second.keySet().size()); }