// Path: sdk/src/main/java/ly/count/android/sdk/UtilsNetworking.java
// protected static String sha256Hash(String toHash) {
//     String hash = null;
//     try {
//         MessageDigest digest = MessageDigest.getInstance("SHA-256");
//         byte[] bytes = toHash.getBytes("UTF-8");
//         digest.update(bytes, 0, bytes.length);
//         bytes = digest.digest();
// 
//         // This is ~55x faster than looping and String.formating()
//         hash = bytesToHex(bytes);
//     } catch (Throwable e) {
//         Countly.sharedInstance().L.e("Cannot tamper-protect params", e);
//     }
//     return hash;
// }


import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static ly.count.android.sdk.UtilsNetworking.sha256Hash;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
        testDeviceId = "123";
    }

    @Test
    public void testConstructorAndGetters() {
        final String serverURL = "https://secureserver";
        final CountlyStore mockStore = mock(CountlyStore.class);
        final DeviceId mockDeviceId = mock(DeviceId.class);
        final ConnectionProcessor connectionProcessor1 = new ConnectionProcessor(serverURL, mockStore, mockDeviceId, null, null, moduleLog);
        assertEquals(serverURL, connectionProcessor1.getServerURL());
        assertSame(mockStore, connectionProcessor1.getCountlyStore());
        assertSame(mockDeviceId, connectionProcessor1.getDeviceId());
    }

    /**
     * Make sure that a correct url is generated
     * No salt provided and no custom endpoint
     *
     * @throws IOException
     */
    @Test
    public void testUrlConnectionForEventData() throws IOException {
        ConnectionProcessor.salt = null;
        final String eventData = "blahblahblah";
        final URLConnection urlConnection = connectionProcessor.urlConnectionForServerRequest(eventData, null);
        assertEquals(30000, urlConnection.getConnectTimeout());
        assertEquals(30000, urlConnection.getReadTimeout());
        assertFalse(urlConnection.getUseCaches());
        assertTrue(urlConnection.getDoInput());
        assertFalse(urlConnection.getDoOutput());
// Path: sdk/src/main/java/ly/count/android/sdk/UtilsNetworking.java
// protected static String sha256Hash(String toHash) {
//     String hash = null;
//     try {
//         MessageDigest digest = MessageDigest.getInstance("SHA-256");
//         byte[] bytes = toHash.getBytes("UTF-8");
//         digest.update(bytes, 0, bytes.length);
//         bytes = digest.digest();
// 
//         // This is ~55x faster than looping and String.formating()
//         hash = bytesToHex(bytes);
//     } catch (Throwable e) {
//         Countly.sharedInstance().L.e("Cannot tamper-protect params", e);
//     }
//     return hash;
// }


// Path: sdk/src/androidTest/java/ly/count/android/sdk/ConnectionProcessorTests.java
import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static ly.count.android.sdk.UtilsNetworking.sha256Hash;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

        testDeviceId = "123";
    }

    @Test
    public void testConstructorAndGetters() {
        final String serverURL = "https://secureserver";
        final CountlyStore mockStore = mock(CountlyStore.class);
        final DeviceId mockDeviceId = mock(DeviceId.class);
        final ConnectionProcessor connectionProcessor1 = new ConnectionProcessor(serverURL, mockStore, mockDeviceId, null, null, moduleLog);
        assertEquals(serverURL, connectionProcessor1.getServerURL());
        assertSame(mockStore, connectionProcessor1.getCountlyStore());
        assertSame(mockDeviceId, connectionProcessor1.getDeviceId());
    }

    /**
     * Make sure that a correct url is generated
     * No salt provided and no custom endpoint
     *
     * @throws IOException
     */
    @Test
    public void testUrlConnectionForEventData() throws IOException {
        ConnectionProcessor.salt = null;
        final String eventData = "blahblahblah";
        final URLConnection urlConnection = connectionProcessor.urlConnectionForServerRequest(eventData, null);
        assertEquals(30000, urlConnection.getConnectTimeout());
        assertEquals(30000, urlConnection.getReadTimeout());
        assertFalse(urlConnection.getUseCaches());
        assertTrue(urlConnection.getDoInput());
        assertFalse(urlConnection.getDoOutput());
        assertEquals(new URL(connectionProcessor.getServerURL() + "/i?" + eventData + "&checksum256=" + sha256Hash(eventData + null)), urlConnection.getURL());