/**
 * The MIT License
 *
 * Copyright for portions of OpenUnirest/uniresr-java are held by Mashape (c) 2013 as part of Kong/unirest-java.
 * All other copyright for OpenUnirest/unirest-java are held by OpenUnirest (c) 2018.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package BehaviorTests;

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.nio.client.HttpAsyncClient;
import unirest.Unirest;
import org.junit.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.IntStream;

import static junit.framework.TestCase.assertNotSame;
import static junit.framework.TestCase.assertSame;

public class DefectTest extends BddTest {

    @Test
    public void hashOnLinksDoNotMessUpUri() {
        Unirest.get(MockServer.GET + "?a=1&b=2#some_location")
                .asObject(RequestCapture.class)
                .getBody()
                .assertParam("a", "1")
                .assertParam("b", "2");
    }

    @Test
    public void nullAndObjectValuesInMap() {
        Map<String, Object> queryParams = new HashMap<>();
        queryParams.put("foo", null);
        queryParams.put("baz", "qux");

        Unirest.get(MockServer.GET)
                .queryString(queryParams)
                .asObject(RequestCapture.class)
                .getBody()
                .assertParam("foo", "")
                .assertParam("baz", "qux")
                .assertQueryString("foo&baz=qux");
    }


    @Test
    public void issue_41_IllegalThreadStateExceptionUnderHighLoad() throws IOException {
        Unirest.get(MockServer.GET).asStringAsync();

        HttpAsyncClient first = Unirest.config().getAsyncHttpClient();
        IntStream.range(1, 50).forEach(i ->{
            assertSame(first, Unirest.config().getAsyncHttpClient());
        });

        ((CloseableHttpAsyncClient)Unirest.config().getAsyncHttpClient()).close();
        Unirest.get(MockServer.GET).asStringAsync();

        HttpAsyncClient second = Unirest.config().getAsyncHttpClient();
        assertNotSame(first, second);

        IntStream.range(1, 50).forEach(i ->{
            assertSame(second, Unirest.config().getAsyncHttpClient());
        });
    }
}

@@ -1437,24 +1437,77 @@
 syncClient;%0A
+import org.json.JSONObject;%0Aimport org.junit.Ignore;%0A
 import unire
@@ -1758,16 +1758,61 @@
 ertSame;
+%0Aimport static org.junit.Assert.assertEquals;
 %0A%0Apublic
@@ -3348,11 +3348,365 @@
 );%0A    %7D
+%0A%0A    @Test @Ignore%0A    public void trySomeoneElsesGZip() throws Exception %7B%0A        JSONObject body = Unirest.get(%22http://httpbin.org/gzip%22)%0A                .asJsonAsync().get().getBody().getObject();%0A%0A        assertEquals(true, body.getBoolean(%22gzipped%22));%0A        assertEquals(%22gzip%22, body.getJSONObject(%22headers%22).getString(%22Accept-Encoding%22));%0A    %7D
 %0A%7D%0A

add test for gzipping