AsyncStorageModule extends ReactContextBaseJavaModule implements ModuleDataCleaner.Cleanable { @ReactMethod public void getAllKeys(final Callback callback) { new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void... params) { if (!ensureDatabase()) { callback.invoke(AsyncStorageErrorUtil.getDBError(null), null); return; } WritableArray data = Arguments.createArray(); String[] columns = {KEY_COLUMN}; Cursor cursor = mReactDatabaseSupplier.get() .query(TABLE_CATALYST, columns, null, null, null, null, null); try { if (cursor.moveToFirst()) { do { data.pushString(cursor.getString(0)); } while (cursor.moveToNext()); } } catch (Exception e) { FLog.w(ReactConstants.TAG, e.getMessage(), e); callback.invoke(AsyncStorageErrorUtil.getError(null, e.getMessage()), null); return; } finally { cursor.close(); } callback.invoke(null, data); } }.execute(); } AsyncStorageModule(ReactApplicationContext reactContext); @Override String getName(); @Override void initialize(); @Override void onCatalystInstanceDestroy(); @Override void clearSensitiveData(); @ReactMethod void multiGet(final ReadableArray keys, final Callback callback); @ReactMethod void multiSet(final ReadableArray keyValueArray, final Callback callback); @ReactMethod void multiRemove(final ReadableArray keys, final Callback callback); @ReactMethod void multiMerge(final ReadableArray keyValueArray, final Callback callback); @ReactMethod void clear(final Callback callback); @ReactMethod void getAllKeys(final Callback callback);  }
@Test public void testGetAllKeys() { final String[] keys = {"foo", "foo2"}; final String[] values = {"bar", "bar2"}; JavaOnlyArray keyValues = new JavaOnlyArray(); keyValues.pushArray(getArray(keys[0], values[0])); keyValues.pushArray(getArray(keys[1], values[1])); mStorage.multiSet(keyValues, mock(Callback.class)); JavaOnlyArray storedKeys = new JavaOnlyArray(); storedKeys.pushString(keys[0]); storedKeys.pushString(keys[1]); Callback getAllCallback = mock(Callback.class); mStorage.getAllKeys(getAllCallback); Mockito.verify(getAllCallback, Mockito.times(1)).invoke(null, storedKeys); Callback getAllCallback2 = mock(Callback.class); mStorage.multiRemove(getArray(keys[0]), mock(Callback.class)); mStorage.getAllKeys(getAllCallback2); Mockito.verify(getAllCallback2, Mockito.times(1)).invoke(null, getArray(keys[1])); mStorage.multiRemove(getArray(keys[1]), mock(Callback.class)); Callback getAllCallback3 = mock(Callback.class); mStorage.getAllKeys(getAllCallback3); Mockito.verify(getAllCallback3, Mockito.times(1)).invoke(null, mEmptyArray); }