// Path: src/main/java/org/dmfs/oauth2/client/OAuth2AccessToken.java
// public interface OAuth2AccessToken
// {
//     /**
//      * Returns the actual access token String.
//      *
//      * @return
//      *
//      * @throws ProtocolException
//      */
//     public CharSequence accessToken() throws ProtocolException;
// 
//     /**
//      * Returns the access token type.
//      *
//      * @return
//      *
//      * @throws ProtocolException
//      */
//     public CharSequence tokenType() throws ProtocolException;
// 
//     /**
//      * Returns whether the response also contained a refresh token.
//      *
//      * @return
//      */
//     public boolean hasRefreshToken();
// 
//     /**
//      * Returns the refresh token. Before calling this use {@link #hasRefreshToken()} to check if there actually is a refresh token.
//      *
//      * @return
//      *
//      * @throws NoSuchElementException
//      *         If the token doesn't contain a refresh token.
//      * @throws ProtocolException
//      */
//     public CharSequence refreshToken() throws ProtocolException;
// 
//     /**
//      * Returns the expected expiration date of the access token.
//      *
//      * @return
//      *
//      * @throws ProtocolException
//      */
//     public DateTime expirationDate() throws ProtocolException;
// 
//     /**
//      * The scope this {@link OAuth2AccessToken} was issued for. May be an empty scope if the scope is not known.
//      *
//      * @return An {@link OAuth2Scope}.
//      *
//      * @throws ProtocolException
//      */
//     public OAuth2Scope scope() throws ProtocolException;
// 
//     /**
//      * Returns a value stored in the token response under the {@code parameterName}.
//      *
//      * @param parameterName
//      *         the key under which the value is stored in the response
//      */
//     public Optional<CharSequence> extraParameter(final String parameterName);
// }
// 
// Path: src/main/java/org/dmfs/oauth2/client/scope/EmptyScope.java
// public final class EmptyScope implements OAuth2Scope
// {
//     public final static EmptyScope INSTANCE = new EmptyScope();
// 
// 
//     @Override
//     public boolean isEmpty()
//     {
//         return true;
//     }
// 
// 
//     @Override
//     public boolean hasToken(String token)
//     {
//         // no tokens in here
//         return false;
//     }
// 
// 
//     @Override
//     public int tokenCount()
//     {
//         return 0;
//     }
// 
// 
//     @Override
//     public String toString()
//     {
//         return "";
//     }
// 
// 
//     @Override
//     public boolean equals(Object obj)
//     {
//         if (!(obj instanceof OAuth2Scope))
//         {
//             return false;
//         }
// 
//         return ((OAuth2Scope) obj).isEmpty();
//     }
// }


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.dmfs.httpessentials.HttpStatus;
import org.dmfs.httpessentials.exceptions.ProtocolError;
import org.dmfs.httpessentials.exceptions.ProtocolException;
import org.dmfs.httpessentials.headers.EmptyHeaders;
import org.dmfs.httpessentials.mockutils.entities.StaticMockResponseEntity;
import org.dmfs.httpessentials.mockutils.responses.StaticMockResponse;
import org.dmfs.httpessentials.types.StructuredMediaType;
import org.dmfs.oauth2.client.OAuth2AccessToken;
import org.dmfs.oauth2.client.scope.EmptyScope;
import org.junit.Test;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
/*
 * Copyright 2016 dmfs GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.dmfs.oauth2.client.http.responsehandlers;





/**
 * Test the {@link TokenResponseHandler}.
 * <p/>
 * TODO: also test some invalid responses.
 *
 * @author Marten Gajda <marten@dmfs.org>
 */
public class TokenResponseHandlerTest
{

    @Test
    public void testHandleResponse() throws UnsupportedEncodingException, IOException, ProtocolError, ProtocolException
    {
        final String accessTokenResponse = "{" + "\"access_token\":\"2YotnFZFEjr1zCsicMWpAA\"," + "\"token_type\":\"example\"," + "\"expires_in\":3600,"
                + "\"refresh_token\":\"tGzv3JOkF0XG5Qx2TlKWIA\"," + "\"example_parameter\":\"example_value\"" + "}";

// Path: src/main/java/org/dmfs/oauth2/client/OAuth2AccessToken.java
// public interface OAuth2AccessToken
// {
//     /**
//      * Returns the actual access token String.
//      *
//      * @return
//      *
//      * @throws ProtocolException
//      */
//     public CharSequence accessToken() throws ProtocolException;
// 
//     /**
//      * Returns the access token type.
//      *
//      * @return
//      *
//      * @throws ProtocolException
//      */
//     public CharSequence tokenType() throws ProtocolException;
// 
//     /**
//      * Returns whether the response also contained a refresh token.
//      *
//      * @return
//      */
//     public boolean hasRefreshToken();
// 
//     /**
//      * Returns the refresh token. Before calling this use {@link #hasRefreshToken()} to check if there actually is a refresh token.
//      *
//      * @return
//      *
//      * @throws NoSuchElementException
//      *         If the token doesn't contain a refresh token.
//      * @throws ProtocolException
//      */
//     public CharSequence refreshToken() throws ProtocolException;
// 
//     /**
//      * Returns the expected expiration date of the access token.
//      *
//      * @return
//      *
//      * @throws ProtocolException
//      */
//     public DateTime expirationDate() throws ProtocolException;
// 
//     /**
//      * The scope this {@link OAuth2AccessToken} was issued for. May be an empty scope if the scope is not known.
//      *
//      * @return An {@link OAuth2Scope}.
//      *
//      * @throws ProtocolException
//      */
//     public OAuth2Scope scope() throws ProtocolException;
// 
//     /**
//      * Returns a value stored in the token response under the {@code parameterName}.
//      *
//      * @param parameterName
//      *         the key under which the value is stored in the response
//      */
//     public Optional<CharSequence> extraParameter(final String parameterName);
// }
// 
// Path: src/main/java/org/dmfs/oauth2/client/scope/EmptyScope.java
// public final class EmptyScope implements OAuth2Scope
// {
//     public final static EmptyScope INSTANCE = new EmptyScope();
// 
// 
//     @Override
//     public boolean isEmpty()
//     {
//         return true;
//     }
// 
// 
//     @Override
//     public boolean hasToken(String token)
//     {
//         // no tokens in here
//         return false;
//     }
// 
// 
//     @Override
//     public int tokenCount()
//     {
//         return 0;
//     }
// 
// 
//     @Override
//     public String toString()
//     {
//         return "";
//     }
// 
// 
//     @Override
//     public boolean equals(Object obj)
//     {
//         if (!(obj instanceof OAuth2Scope))
//         {
//             return false;
//         }
// 
//         return ((OAuth2Scope) obj).isEmpty();
//     }
// }


// Path: src/test/java/org/dmfs/oauth2/client/http/responsehandlers/TokenResponseHandlerTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.dmfs.httpessentials.HttpStatus;
import org.dmfs.httpessentials.exceptions.ProtocolError;
import org.dmfs.httpessentials.exceptions.ProtocolException;
import org.dmfs.httpessentials.headers.EmptyHeaders;
import org.dmfs.httpessentials.mockutils.entities.StaticMockResponseEntity;
import org.dmfs.httpessentials.mockutils.responses.StaticMockResponse;
import org.dmfs.httpessentials.types.StructuredMediaType;
import org.dmfs.oauth2.client.OAuth2AccessToken;
import org.dmfs.oauth2.client.scope.EmptyScope;
import org.junit.Test;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

/*
 * Copyright 2016 dmfs GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.dmfs.oauth2.client.http.responsehandlers;





/**
 * Test the {@link TokenResponseHandler}.
 * <p/>
 * TODO: also test some invalid responses.
 *
 * @author Marten Gajda <marten@dmfs.org>
 */
public class TokenResponseHandlerTest
{

    @Test
    public void testHandleResponse() throws UnsupportedEncodingException, IOException, ProtocolError, ProtocolException
    {
        final String accessTokenResponse = "{" + "\"access_token\":\"2YotnFZFEjr1zCsicMWpAA\"," + "\"token_type\":\"example\"," + "\"expires_in\":3600,"
                + "\"refresh_token\":\"tGzv3JOkF0XG5Qx2TlKWIA\"," + "\"example_parameter\":\"example_value\"" + "}";

        OAuth2AccessToken token = new TokenResponseHandler(EmptyScope.INSTANCE).handleResponse(