// Path: here-oauth-client/src/main/java/com/here/account/util/JsonSerializer.java
// public class JsonSerializer {
// 
//     /**
//      * The name of the UTF-8 {@link #CHARSET}.
//      */
//     public static final String CHARSET_STRING = "UTF-8";
// 
//     /**
//      * Constant for the loaded UTF-8 Charset.
//      */
//     public static final Charset CHARSET = Charset.forName(CHARSET_STRING);
//     
//     private static ObjectMapper objectMapper = new ObjectMapper();
// 
//     static {
//         objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//         objectMapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true);
//         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//     }
//     
//     /**
//      * Converts the input JSON InputStream, to a Map&lt;String, Object&gt;.
//      * 
//      * @param jsonInputStream the input stream to the JSON object
//      * @return its Map representation
//      * @throws IOException if trouble deserializing
//      */
//     public static Map<String, Object> toMap(InputStream jsonInputStream) throws IOException {
//         return (HashMap<String, Object>) objectMapper.readValue(jsonInputStream, HashMap.class);
//     }
//     
//     /**
//      * Converts the input JSON InputStream, to a POJO of the class specified as pojoClass.
//      * 
//      * @param <T> the type of the POJO
//      * @param jsonInputStream the input stream to the JSON object
//      * @param pojoClass the class to deserialize into
//      * @return the instance of the pojoClass with member variables populated
//      * @throws JsonParseException if trouble parsing
//      * @throws JsonMappingException if trouble mapping
//      * @throws IOException if trouble deserializing
//      */
//     public static <T> T toPojo (InputStream jsonInputStream, Class<T> pojoClass) throws JsonParseException, JsonMappingException, IOException {
//         return objectMapper.readValue(jsonInputStream, pojoClass);
//     }
//     
//     /**
//      * Converts the input mapObject to its JSON String representation.
//      * 
//      * @param mapObject the json's Map representation
//      * @return the JSON String representation of the input.
//      * @throws JsonProcessingException if an exception from the jackson serializer
//      */
//     public static String toJson(Map<String, Object> mapObject) throws JsonProcessingException {
//         return objectMapper.writeValueAsString(mapObject);
//     }
//     
//     /**
//      * Converts the input POJO object to its JSON string.
//      * 
//      * @param object the object to serialize into a JSON string.
//      * @return the JSON string representation of the object.
//      * @throws JsonProcessingException if there's trouble serializing object 
//      *      to a JSON string.
//      */
//     public static String objectToJson(Object object) throws JsonProcessingException {
//         return objectMapper.writeValueAsString(object);
//     }
//     
//     /**
//      * Writes the object to the specified outputStream as JSON.
//      * 
//      * @param outputStream the OutputStream to which to write
//      * @param object the object to write to the stream
//      * @throws JsonGenerationException if trouble serializing
//      * @throws JsonMappingException if trouble serializing
//      * @throws IOException if I/O trouble writing to the stream
//      */
//     static void writeObjectToJson(OutputStream outputStream, Object object) throws JsonGenerationException, JsonMappingException, IOException {
//         objectMapper.writeValue(outputStream, object);
//     }
// 
// }
// 
// Path: here-oauth-client/src/main/java/com/here/account/util/OAuthConstants.java
// public class OAuthConstants {
//     
//     /**
//      * We commonly use "UTF-8" charset, this String is its name.
//      */
//     public static final String UTF_8_STRING = "UTF-8";
//     
//     /**
//      * This is the constant for the "UTF-8" Charset already loaded.
//      */
//     public static final Charset UTF_8_CHARSET = Charset.forName(UTF_8_STRING);
// }


import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import com.here.account.util.JsonSerializer;
import com.here.account.util.OAuthConstants;
    @Test
    public void test_ClientCredentialsGrantRequest_form() {
        ClientCredentialsGrantRequest clientCredentialsGrantRequest = new ClientCredentialsGrantRequest();
        Map<String, List<String>> form = clientCredentialsGrantRequest.toFormParams();
        Map<String, List<String>> expectedForm = new HashMap<String, List<String>>();
        expectedForm.put("grant_type", Collections.singletonList("client_credentials"));
        assertTrue("expected form "+expectedForm+", actual "+form, expectedForm.equals(form));
    }
    
    @Test
    public void test_ClientCredentialsGrantRequest_form_expiresIn() throws IOException {
        long expiresIn = 15;
        String scope = "test scope";
        ClientCredentialsGrantRequest clientCredentialsGrantRequest = new
                ClientCredentialsGrantRequest().setExpiresIn(expiresIn);
        clientCredentialsGrantRequest.setScope(scope);
        Map<String, List<String>> form = clientCredentialsGrantRequest.toFormParams();
        Map<String, List<String>> expectedForm = new HashMap<String, List<String>>();
        expectedForm.put("grant_type", Collections.singletonList("client_credentials"));
        expectedForm.put("expires_in", Collections.singletonList(""+expiresIn));
        expectedForm.put("scope", Collections.singletonList(scope));
        assertTrue("expected form "+expectedForm+", actual "+form, expectedForm.equals(form));
    }


    private Map<String, Object> toMap(String json) throws IOException {
        byte[] bytes = json.getBytes(OAuthConstants.UTF_8_CHARSET);
        ByteArrayInputStream jsonInputStream = null;
        try {
            jsonInputStream = new ByteArrayInputStream(bytes);
// Path: here-oauth-client/src/main/java/com/here/account/util/JsonSerializer.java
// public class JsonSerializer {
// 
//     /**
//      * The name of the UTF-8 {@link #CHARSET}.
//      */
//     public static final String CHARSET_STRING = "UTF-8";
// 
//     /**
//      * Constant for the loaded UTF-8 Charset.
//      */
//     public static final Charset CHARSET = Charset.forName(CHARSET_STRING);
//     
//     private static ObjectMapper objectMapper = new ObjectMapper();
// 
//     static {
//         objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//         objectMapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true);
//         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//     }
//     
//     /**
//      * Converts the input JSON InputStream, to a Map&lt;String, Object&gt;.
//      * 
//      * @param jsonInputStream the input stream to the JSON object
//      * @return its Map representation
//      * @throws IOException if trouble deserializing
//      */
//     public static Map<String, Object> toMap(InputStream jsonInputStream) throws IOException {
//         return (HashMap<String, Object>) objectMapper.readValue(jsonInputStream, HashMap.class);
//     }
//     
//     /**
//      * Converts the input JSON InputStream, to a POJO of the class specified as pojoClass.
//      * 
//      * @param <T> the type of the POJO
//      * @param jsonInputStream the input stream to the JSON object
//      * @param pojoClass the class to deserialize into
//      * @return the instance of the pojoClass with member variables populated
//      * @throws JsonParseException if trouble parsing
//      * @throws JsonMappingException if trouble mapping
//      * @throws IOException if trouble deserializing
//      */
//     public static <T> T toPojo (InputStream jsonInputStream, Class<T> pojoClass) throws JsonParseException, JsonMappingException, IOException {
//         return objectMapper.readValue(jsonInputStream, pojoClass);
//     }
//     
//     /**
//      * Converts the input mapObject to its JSON String representation.
//      * 
//      * @param mapObject the json's Map representation
//      * @return the JSON String representation of the input.
//      * @throws JsonProcessingException if an exception from the jackson serializer
//      */
//     public static String toJson(Map<String, Object> mapObject) throws JsonProcessingException {
//         return objectMapper.writeValueAsString(mapObject);
//     }
//     
//     /**
//      * Converts the input POJO object to its JSON string.
//      * 
//      * @param object the object to serialize into a JSON string.
//      * @return the JSON string representation of the object.
//      * @throws JsonProcessingException if there's trouble serializing object 
//      *      to a JSON string.
//      */
//     public static String objectToJson(Object object) throws JsonProcessingException {
//         return objectMapper.writeValueAsString(object);
//     }
//     
//     /**
//      * Writes the object to the specified outputStream as JSON.
//      * 
//      * @param outputStream the OutputStream to which to write
//      * @param object the object to write to the stream
//      * @throws JsonGenerationException if trouble serializing
//      * @throws JsonMappingException if trouble serializing
//      * @throws IOException if I/O trouble writing to the stream
//      */
//     static void writeObjectToJson(OutputStream outputStream, Object object) throws JsonGenerationException, JsonMappingException, IOException {
//         objectMapper.writeValue(outputStream, object);
//     }
// 
// }
// 
// Path: here-oauth-client/src/main/java/com/here/account/util/OAuthConstants.java
// public class OAuthConstants {
//     
//     /**
//      * We commonly use "UTF-8" charset, this String is its name.
//      */
//     public static final String UTF_8_STRING = "UTF-8";
//     
//     /**
//      * This is the constant for the "UTF-8" Charset already loaded.
//      */
//     public static final Charset UTF_8_CHARSET = Charset.forName(UTF_8_STRING);
// }


// Path: here-oauth-client/src/test/java/com/here/account/oauth2/ClientCredentialsGrantRequestTest.java
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import com.here.account.util.JsonSerializer;
import com.here.account.util.OAuthConstants;

    @Test
    public void test_ClientCredentialsGrantRequest_form() {
        ClientCredentialsGrantRequest clientCredentialsGrantRequest = new ClientCredentialsGrantRequest();
        Map<String, List<String>> form = clientCredentialsGrantRequest.toFormParams();
        Map<String, List<String>> expectedForm = new HashMap<String, List<String>>();
        expectedForm.put("grant_type", Collections.singletonList("client_credentials"));
        assertTrue("expected form "+expectedForm+", actual "+form, expectedForm.equals(form));
    }
    
    @Test
    public void test_ClientCredentialsGrantRequest_form_expiresIn() throws IOException {
        long expiresIn = 15;
        String scope = "test scope";
        ClientCredentialsGrantRequest clientCredentialsGrantRequest = new
                ClientCredentialsGrantRequest().setExpiresIn(expiresIn);
        clientCredentialsGrantRequest.setScope(scope);
        Map<String, List<String>> form = clientCredentialsGrantRequest.toFormParams();
        Map<String, List<String>> expectedForm = new HashMap<String, List<String>>();
        expectedForm.put("grant_type", Collections.singletonList("client_credentials"));
        expectedForm.put("expires_in", Collections.singletonList(""+expiresIn));
        expectedForm.put("scope", Collections.singletonList(scope));
        assertTrue("expected form "+expectedForm+", actual "+form, expectedForm.equals(form));
    }


    private Map<String, Object> toMap(String json) throws IOException {
        byte[] bytes = json.getBytes(OAuthConstants.UTF_8_CHARSET);
        ByteArrayInputStream jsonInputStream = null;
        try {
            jsonInputStream = new ByteArrayInputStream(bytes);
            return JsonSerializer.toMap(jsonInputStream);