CsrfTokenClient { public void request(@NonNull final Callback callback) { request(false, callback); } CsrfTokenClient(@NonNull WikiSite csrfWikiSite, @NonNull WikiSite loginWikiSite); void request(@NonNull final Callback callback); void request(boolean forceLogin, @NonNull final Callback callback); void cancel(); @NonNull String getTokenBlocking();  }
@Test public void testRequestSuccess() throws Throwable { String expected = "b6f7bd58c013ab30735cb19ecc0aa08258122cba+\\"; enqueueFromFile("csrf_token.json"); Callback cb = mock(Callback.class); request(cb); server().takeRequest(); assertCallbackSuccess(cb, expected); }
@Test public void testRequestResponseApiError() throws Throwable { enqueueFromFile("api_error.json"); Callback cb = mock(Callback.class); request(cb); server().takeRequest(); assertCallbackFailure(cb, MwException.class); }
@Test public void testRequestResponseFailure() throws Throwable { enqueue404(); Callback cb = mock(Callback.class); request(cb); server().takeRequest(); assertCallbackFailure(cb, HttpStatusException.class); }
@Test public void testRequestResponseMalformed() throws Throwable { enqueueMalformed(); Callback cb = mock(Callback.class); request(cb); server().takeRequest(); assertCallbackFailure(cb, MalformedJsonException.class); }