EditClient { @SuppressWarnings("checkstyle:parameternumber") public Call<Edit> request(@NonNull WikiSite wiki, @NonNull PageTitle title, int section, @NonNull String text, @NonNull String token, @NonNull String summary, @Nullable String baseTimeStamp, boolean loggedIn, @Nullable String captchaId, @Nullable String captchaWord, @NonNull Callback cb) { return request(ServiceFactory.get(wiki), title, section, text, token, summary, baseTimeStamp, loggedIn, captchaId, captchaWord, cb); }  @SuppressWarnings("checkstyle:parameternumber") Call<Edit> request(@NonNull WikiSite wiki, @NonNull PageTitle title, int section,
                              @NonNull String text, @NonNull String token, @NonNull String summary,
                              @Nullable String baseTimeStamp, boolean loggedIn, @Nullable String captchaId,
                              @Nullable String captchaWord, @NonNull Callback cb);  }
@Test @SuppressWarnings("checkstyle:magicnumber") public void testRequestSuccessHasResults() throws Throwable { EditSuccessResult expected = new EditSuccessResult(761350490); enqueueFromFile("edit_result_success.json"); EditClient.Callback cb = mock(EditClient.Callback.class); Call<Edit> call = request(cb, false); server().takeRequest(); assertCallbackSuccess(call, cb, expected); }
@Test public void testRequestResponseAbuseFilter() throws Throwable { EditAbuseFilterResult expected = new EditAbuseFilterResult("abusefilter-disallowed", "Hit AbuseFilter: Editing user page by anonymous user", "<b>Warning:</b> This action has been automatically identified as harmful.\nUnconstructive edits will be quickly reverted,\nand egregious or repeated unconstructive editing will result in your account or IP address being blocked.\nIf you believe this action to be constructive, you may submit it again to confirm it.\nA brief description of the abuse rule which your action matched is: Editing user page by anonymous user"); enqueueFromFile("edit_abuse_filter_result.json"); EditClient.Callback cb = mock(EditClient.Callback.class); Call<Edit> call = request(cb, false); server().takeRequest(); assertCallbackSuccess(call, cb, expected); }
@Test public void testRequestResponseSpamBlacklist() throws Throwable { EditSpamBlacklistResult expected = new EditSpamBlacklistResult("s-e-x"); enqueueFromFile("edit_result_spam_blacklist.json"); EditClient.Callback cb = mock(EditClient.Callback.class); Call<Edit> call = request(cb, false); server().takeRequest(); assertCallbackSuccess(call, cb, expected); }
@Test @SuppressWarnings("checkstyle:magicnumber") public void testRequestResponseCaptcha() throws Throwable { CaptchaResult expected = new CaptchaResult("547159230"); enqueueFromFile("edit_result_captcha.json"); EditClient.Callback cb = mock(EditClient.Callback.class); Call<Edit> call = request(cb, false); server().takeRequest(); assertCallbackSuccess(call, cb, expected); }
@Test public void testRequestResponseAssertUserFailed() throws Throwable { enqueueFromFile("api_error_assert_user_failed.json"); EditClient.Callback cb = mock(EditClient.Callback.class); Call<Edit> call = request(cb, true); server().takeRequest(); assertCallbackFailure(call, cb, MwException.class); }
@Test public void testRequestResponseGenericApiError() throws Throwable { enqueueFromFile("api_error.json"); EditClient.Callback cb = mock(EditClient.Callback.class); Call<Edit> call = request(cb, false); server().takeRequest(); assertCallbackFailure(call, cb, MwException.class); }
@Test public void testRequestResponseApiError() throws Throwable { enqueueFromFile("api_error.json"); EditClient.Callback cb = mock(EditClient.Callback.class); Call<Edit> call = request(cb, false); server().takeRequest(); assertCallbackFailure(call, cb, MwException.class); }
@Test public void testRequestResponse404() throws Throwable { enqueue404(); EditClient.Callback cb = mock(EditClient.Callback.class); Call<Edit> call = request(cb, false); server().takeRequest(); assertCallbackFailure(call, cb, HttpStatusException.class); }
@Test public void testRequestResponseMalformed() throws Throwable { enqueueMalformed(); EditClient.Callback cb = mock(EditClient.Callback.class); Call<Edit> call = request(cb, false); server().takeRequest(); assertCallbackFailure(call, cb, MalformedJsonException.class); }