OAuth1aInterceptor implements Interceptor { Map<String, String> getPostParams(Request request) throws IOException { final Map<String, String> params = new HashMap<>(); if ("POST".equals(request.method().toUpperCase(Locale.US))) { final RequestBody output = request.body(); if (output instanceof FormBody) { final FormBody body = (FormBody) output; for (int i = 0; i < body.size(); i++) { params.put(body.encodedName(i), body.value(i)); } } } return params; } OAuth1aInterceptor(Session<? extends TwitterAuthToken> session,
            TwitterAuthConfig authConfig); @Override Response intercept(Chain chain);  }
@Test public void testGetPostParameters_bodyWithMultipleParams() throws IOException { final FormBody formBody = new FormBody.Builder() .add(POST_KEY, POST_VALUE) .add(POST_KEY_2, POST_VALUE_2) .build(); final Request request = new Request.Builder() .url(TEST_URL) .post(formBody) .build(); final Map<String, String> params = interceptor.getPostParams(request); assertEquals(2, params.size()); assertEquals(POST_VALUE, params.get(POST_KEY)); assertEquals(POST_VALUE_2, params.get(POST_KEY_2_ENCODED)); }
@Test public void testGetPostParameters_withZeroParams() throws IOException { final FormBody formBody = new FormBody.Builder().build(); final Request request = new Request.Builder() .url(TEST_URL) .post(formBody) .build(); final Map<String, String> params = interceptor.getPostParams(request); assertEquals(0, params.size()); }
@Test public void testGetPostParameters_withGetRequest() throws IOException { final Request request = new Request.Builder().url(TEST_URL).build(); final Map<String, String> params = interceptor.getPostParams(request); assertEquals(0, params.size()); }