AsyncStorageModule extends ReactContextBaseJavaModule implements ModuleDataCleaner.Cleanable { @ReactMethod public void clear(final Callback callback) { new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void... params) { if (!mReactDatabaseSupplier.ensureDatabase()) { callback.invoke(AsyncStorageErrorUtil.getDBError(null)); return; } try { mReactDatabaseSupplier.clear(); callback.invoke(); } catch (Exception e) { FLog.w(ReactConstants.TAG, e.getMessage(), e); callback.invoke(AsyncStorageErrorUtil.getError(null, e.getMessage())); } } }.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 testClear() { JavaOnlyArray keyValues = new JavaOnlyArray(); keyValues.pushArray(getArray("foo", "foo2")); keyValues.pushArray(getArray("bar", "bar2")); mStorage.multiSet(keyValues, mock(Callback.class)); Callback clearCallback2 = mock(Callback.class); mStorage.clear(clearCallback2); Mockito.verify(clearCallback2, Mockito.times(1)).invoke(); Callback getAllCallback2 = mock(Callback.class); mStorage.getAllKeys(getAllCallback2); Mockito.verify(getAllCallback2, Mockito.times(1)).invoke(null, mEmptyArray); }