/** loadOAuthParameters */
  @Test
  public void testLoadOAuthParameters() throws Exception {
    ProtectedResourceDetails details = createMock(ProtectedResourceDetails.class);
    URL url = new URL("https://myhost.com/somepath?with=some&query=params&too");
    CoreOAuthConsumerSupport support =
        new CoreOAuthConsumerSupport() {
          @Override
          protected String getSignatureBaseString(
              Map<String, Set<CharSequence>> oauthParams, URL requestURL, String httpMethod) {
            return "MYSIGBASESTRING";
          }
        };
    OAuthSignatureMethodFactory sigFactory = createMock(OAuthSignatureMethodFactory.class);
    support.setSignatureFactory(sigFactory);
    OAuthConsumerToken token = new OAuthConsumerToken();
    OAuthSignatureMethod sigMethod = createMock(OAuthSignatureMethod.class);

    expect(details.getConsumerKey()).andReturn("my-consumer-key");
    expect(details.getSignatureMethod()).andReturn(HMAC_SHA1SignatureMethod.SIGNATURE_NAME);
    expect(details.getSignatureMethod()).andReturn(HMAC_SHA1SignatureMethod.SIGNATURE_NAME);
    SharedConsumerSecret secret = new SharedConsumerSecret("shh!!!");
    expect(details.getSharedSecret()).andReturn(secret);
    expect(sigFactory.getSignatureMethod(HMAC_SHA1SignatureMethod.SIGNATURE_NAME, secret, null))
        .andReturn(sigMethod);
    expect(sigMethod.sign("MYSIGBASESTRING")).andReturn("MYSIGNATURE");

    replay(details, sigFactory, sigMethod);
    Map<String, Set<CharSequence>> params =
        support.loadOAuthParameters(details, url, token, "POST", null);
    verify(details, sigFactory, sigMethod);
    reset(details, sigFactory, sigMethod);
    assertEquals("some", params.remove("with").iterator().next().toString());
    assertEquals("params", params.remove("query").iterator().next().toString());
    assertTrue(params.containsKey("too"));
    assertTrue(params.remove("too").isEmpty());
    assertNull(params.remove(OAuthConsumerParameter.oauth_token.toString()));
    assertNotNull(params.remove(OAuthConsumerParameter.oauth_nonce.toString()).iterator().next());
    assertEquals(
        "my-consumer-key",
        params.remove(OAuthConsumerParameter.oauth_consumer_key.toString()).iterator().next());
    assertEquals(
        "MYSIGNATURE",
        params.remove(OAuthConsumerParameter.oauth_signature.toString()).iterator().next());
    assertEquals(
        "1.0", params.remove(OAuthConsumerParameter.oauth_version.toString()).iterator().next());
    assertEquals(
        HMAC_SHA1SignatureMethod.SIGNATURE_NAME,
        params.remove(OAuthConsumerParameter.oauth_signature_method.toString()).iterator().next());
    assertTrue(
        Long.parseLong(
                params
                    .remove(OAuthConsumerParameter.oauth_timestamp.toString())
                    .iterator()
                    .next()
                    .toString())
            <= (System.currentTimeMillis() / 1000));
    assertTrue(params.isEmpty());
  }