### Question:
ResponseParser { public static String toURLEncoded(final Class givenClass, final Object obj) { Field[] fields = givenClass.getDeclaredFields(); StringBuilder response = new StringBuilder(); boolean firstLoop = true; for (Field field: fields) { String parameterPair; try { if (field.isAccessible()) parameterPair = publicField(obj, field); else parameterPair = nonPublicField(givenClass, obj, field); if (firstLoop) { firstLoop = false; response.append(parameterPair); } else response.append("&").append(parameterPair); } catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) { e.printStackTrace(); throw new RuntimeException("Unexpected error on response" + " parsing"); } } return response.toString(); } private  ResponseParser(); static String toURLEncoded(final Class givenClass,
            final Object obj); static String publicField(final Object obj, final Field field); static String nonPublicField(final Class givenClass,
            final Object obj, final Field field); static void publicField(final String parameterName,
            final String parameterValue, final Class givenClass,
            final Object obj); static void nonPublicField(final String parameterName,
            final String parameterValue, final Class givenClass,
            final Object obj); static Object toObject(final String response,
            final Class givenClass); static String encodeParameter(final String parameterName,
            final String parameterValue);  }### Answer:
@Test public void testParseResponse() { RequestToken requestToken = new RequestToken("fd fd", "fh"); String response = ResponseParser.toURLEncoded(RequestToken.class, requestToken); assertEquals(response, "request_token=fd%20%20fd&token_secret=fh&authorized=false"); ClientCredentials clientCredentials = new ClientCredentials("client id", "client secret"); response = ResponseParser.toURLEncoded(ClientCredentials.class, clientCredentials); assertEquals(response, "client_id=client%20id&client_secret=client%20secret"); EncryptionKey encryptionKey = new EncryptionKey("key content"); response = ResponseParser.toURLEncoded(EncryptionKey.class, encryptionKey); assertEquals(response, "encryption_key=key%20content"); }
@Test(expected = RuntimeException.class) public void testParseResponseRuntimeException() { ResponseParser.toURLEncoded(EncryptionKey.class, new TestClass()); }