RNInstabugSurveysModule extends ReactContextBaseJavaModule { @ReactMethod public void getAvailableSurveys(final Callback availableSurveysCallback) { MainThreadHandler.runOnMainThread(new Runnable() { @Override public void run() { try { List<Survey> availableSurveys = Surveys.getAvailableSurveys(); JSONArray surveysArray = InstabugUtil.surveyObjectToJson(availableSurveys); WritableArray array = ArrayUtil.convertJsonToWritableArray(surveysArray); availableSurveysCallback.invoke(array); } catch (Exception e) { e.printStackTrace(); } } }); } RNInstabugSurveysModule(ReactApplicationContext reactContext); @Nonnull @Override String getName(); @ReactMethod void hasRespondedToSurvey(final String surveyToken, final Callback hasRespondedCallback); @ReactMethod void showSurvey(final String surveyToken); @ReactMethod void showSurveysIfAvailable(); @ReactMethod void setEnabled(final boolean isEnabled); @ReactMethod void setOnShowHandler(final Callback handler); @ReactMethod void setOnDismissHandler(final Callback handler); @ReactMethod void setThresholdForReshowingSurveyAfterDismiss(final int sessionsCount, final int daysCount); @ReactMethod void getAvailableSurveys(final Callback availableSurveysCallback); @ReactMethod void setAutoShowingEnabled(final boolean autoShowingSurveysEnabled); @ReactMethod void setShouldShowWelcomeScreen(final boolean shouldShow);  }
@Test public void given$getAvailableSurveys_whenQuery_thenShouldCallNativeApiAndInvokeCallback() throws Exception { PowerMockito.mockStatic(Surveys.class); PowerMockito.mockStatic(SystemClock.class); PowerMockito.mockStatic(Arguments.class); Callback callback = mock(Callback.class); JSONArray json = mock(JSONArray.class); PowerMockito.whenNew(JSONArray.class).withAnyArguments().thenReturn(json); PowerMockito.when(Arguments.createArray()).thenReturn(new JavaOnlyArray()); surveysModule.getAvailableSurveys(callback); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); Surveys.getAvailableSurveys(); verify(callback).invoke(any()); }