private Pair<JobCallback, Bundle> extractCallback(Bundle bundle) { return extractor.extractCallback(bundle); }
Bundle testBundle = new Bundle(); testBundle.putString(expectedKey, "value"); Parcel testParcel = toParcel(testBundle); try { checkCondition(testParcel.readInt() > 0); checkCondition(testParcel.readInt() == BUNDLE_MAGIC); checkCondition(testParcel.readInt() == 1);
public Pair<JobCallback, Bundle> extractCallback(@Nullable Bundle data) { if (data == null) { Log.e(TAG, ERROR_NULL_CALLBACK); return null; } return extractWrappedBinderFromParcel(data); }
/** * Reads the next key (String) from the provided {@code serialized} Parcel. * * <p>Naively using {@link Parcel#readString()} fails on versions of Android older than L, whereas * {@link Parcel#readValue(ClassLoader)} works on older versions but fails on anything L or newer. */ private static String readKey(Parcel serialized) { if (shouldReadKeysAsStrings()) { return serialized.readString(); } // Older platforms require readValue @SuppressLint("ParcelClassLoader") // We're just reading a string Object entryKeyObj = serialized.readValue(null /* Use the system ClassLoader */); if (!(entryKeyObj instanceof String)) { // Should never happen (Bundle keys are always Strings) Log.w(TAG, ERROR_INVALID_CALLBACK); return null; } return (String) entryKeyObj; }
@Before public void setUp() { MockitoAnnotations.initMocks(this); extractor = new GooglePlayCallbackExtractor(); }
@Nullable @VisibleForTesting JobInvocation prepareJob(Intent intent) { Bundle intentExtras = intent.getExtras(); if (intentExtras == null) { Log.e(TAG, ERROR_NO_DATA); return null; } // get the callback first. If we don't have this we can't talk back to the backend. Pair<JobCallback, Bundle> extraction = callbackExtractor.extractCallback(intentExtras); if (extraction == null) { Log.i(TAG, "no callback found"); return null; } return prepareJob(extraction.first, extraction.second); }
@Test public void testExtractCallback_nullBundle() { assertNull(extractor.extractCallback(null)); }