<commit_before>package com.webtrekk.webtrekksdk;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.test.AndroidTestCase;

import static org.mockito.Mockito.*;

import com.webtrekk.webtrekksdk.Request.RequestFactory;
import com.webtrekk.webtrekksdk.Request.RequestUrlStore;
import com.webtrekk.webtrekksdk.Request.TrackingRequest;
import com.webtrekk.webtrekksdk.TrackingParameter.Parameter;
import com.webtrekk.webtrekksdk.Configuration.ActivityConfiguration;
import com.webtrekk.webtrekksdk.Utils.HelperFunctions;
import com.webtrekk.webtrekksdk.Configuration.TrackingConfiguration;

import java.util.HashMap;


public class WebtrekkTests extends AndroidTestCase {

    Webtrekk webtrekk;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        // android bug workaround: 308
        System.setProperty("dexmaker.dexcache", getContext().getCacheDir().toString());

        webtrekk = new Webtrekk();
        SharedPreferences.Editor editor = getContext().getSharedPreferences(Webtrekk.PREFERENCE_FILE_NAME, Context.MODE_PRIVATE).edit();
        editor.clear();
        editor.commit();

    }

    @Override
    protected void tearDown() throws Exception {
        RequestUrlStore request = new RequestUrlStore(getContext());
        request.deleteRequestsFile();
        super.tearDown();
    }

    public void testGetInstance() {
        Webtrekk webtrekk = Webtrekk.getInstance();
        assertNotNull(webtrekk);
        // make shure it always returns the same object
        assertSame(webtrekk, Webtrekk.getInstance());
    }

    public void testInitWebtrekk() {
        try {
            webtrekk.initWebtrekk(null);
            fail("null context, IllegalArgumentException");
        } catch (IllegalArgumentException e){

        }

        webtrekk.initWebtrekk(getContext());
        TrackedActivityLifecycleCallbacks callbacks = new TrackedActivityLifecycleCallbacks(webtrekk);
        assertNotNull(webtrekk.getTrackingConfiguration());
        assertNotNull(webtrekk.getContext());
        assertNotNull(webtrekk.getRequestFactory().getRequestUrlStore());
        assertNotNull(webtrekk.getRequestFactory().getWebtrekkParameter());
        assertEquals(0, webtrekk.getActivityCount());
        // make shure it fails when init is called twice
//        try {
//            webtrekk.initWebtrekk(getContext());
//            fail("already initalized, IllegalStateException");
//        } catch (IllegalStateException e) {
//
//        }

    }

    public void testInitTrackingConfiguration() {
        webtrekk.setContext(getContext());
        webtrekk.initTrackingConfiguration(R.raw.webtrekk_config);
        assertNotNull(webtrekk.getTrackingConfiguration());
        assertEquals(webtrekk.getTrackingConfiguration().getTrackId(), "1111111111112");
        assertEquals(webtrekk.getTrackingConfiguration().getTrackDomain(), "http://trackingtest.nglab.org");
        assertEquals(webtrekk.getTrackingConfiguration().getSendDelay(), 30);
        assertEquals(webtrekk.getTrackingConfiguration().getMaxRequests(), 4000);
        assertEquals(webtrekk.getTrackingConfiguration().getVersion(), 3);

    }
    public void testInitWebtrekkParameter() {
        // make sure the default params have valid values
        webtrekk.setContext(getContext());
        webtrekk.initTrackingConfiguration(R.raw.webtrekk_config);
        webtrekk.getRequestFactory().init(mContext, webtrekk.getTrackingConfiguration(), webtrekk);
        assertEquals(6, webtrekk.getRequestFactory().getWebtrekkParameter().size());
        assertTrue(webtrekk.getRequestFactory().getWebtrekkParameter().get(TrackingParameter.Parameter.USERAGENT).contains("Tracking Library " + Webtrekk.mTrackingLibraryVersionUI + "(Android;"));
    }

    public void testUpdateDynamicParameter() {
        // make sure that the values which change with every request are inserted as well
        webtrekk.setContext(getContext());
        webtrekk.initTrackingConfiguration(R.raw.webtrekk_config);
        webtrekk.getRequestFactory().init(mContext, webtrekk.getTrackingConfiguration(), webtrekk);

        RequestUrlStore requestUrlStore = mock(RequestUrlStore.class);
        webtrekk.getRequestFactory().setRequestUrlStore(requestUrlStore);
        when(requestUrlStore.size()).thenReturn(55);

        //set some different default values
        webtrekk.getCustomParameter().put("screenOrientation", "stttr");
        webtrekk.getCustomParameter().put("connectionType", "offline");

        webtrekk.getRequestFactory().updateDynamicParameter();
        assertEquals(7, webtrekk.getRequestFactory().getWebtrekkParameter().size());
        assertTrue(webtrekk.getRequestFactory().getAutoCustomParameter().get("screenOrientation").matches("(portrait|landscape)"));
        String connectionType = webtrekk.getCustomParameter().get("connectionType");
        assertTrue(connectionType.equals("WIFI") || connectionType.equals("offline"));
        assertEquals("55", webtrekk.getRequestFactory().getAutoCustomParameter().get("requestUrlStoreSize"));<commit_msg>FE-17916 fix tests by removing old check for user agent<commit_after>package com.webtrekk.webtrekksdk;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.test.AndroidTestCase;

import static org.mockito.Mockito.*;

import com.webtrekk.webtrekksdk.Request.RequestFactory;
import com.webtrekk.webtrekksdk.Request.RequestUrlStore;
import com.webtrekk.webtrekksdk.Request.TrackingRequest;
import com.webtrekk.webtrekksdk.TrackingParameter.Parameter;
import com.webtrekk.webtrekksdk.Configuration.ActivityConfiguration;
import com.webtrekk.webtrekksdk.Utils.HelperFunctions;
import com.webtrekk.webtrekksdk.Configuration.TrackingConfiguration;

import java.util.HashMap;


public class WebtrekkTests extends AndroidTestCase {

    Webtrekk webtrekk;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        // android bug workaround: 308
        System.setProperty("dexmaker.dexcache", getContext().getCacheDir().toString());

        webtrekk = new Webtrekk();
        SharedPreferences.Editor editor = getContext().getSharedPreferences(Webtrekk.PREFERENCE_FILE_NAME, Context.MODE_PRIVATE).edit();
        editor.clear();
        editor.commit();

    }

    @Override
    protected void tearDown() throws Exception {
        RequestUrlStore request = new RequestUrlStore(getContext());
        request.deleteRequestsFile();
        super.tearDown();
    }

    public void testGetInstance() {
        Webtrekk webtrekk = Webtrekk.getInstance();
        assertNotNull(webtrekk);
        // make shure it always returns the same object
        assertSame(webtrekk, Webtrekk.getInstance());
    }

    public void testInitWebtrekk() {
        try {
            webtrekk.initWebtrekk(null);
            fail("null context, IllegalArgumentException");
        } catch (IllegalArgumentException e){

        }

        webtrekk.initWebtrekk(getContext());
        TrackedActivityLifecycleCallbacks callbacks = new TrackedActivityLifecycleCallbacks(webtrekk);
        assertNotNull(webtrekk.getTrackingConfiguration());
        assertNotNull(webtrekk.getContext());
        assertNotNull(webtrekk.getRequestFactory().getRequestUrlStore());
        assertNotNull(webtrekk.getRequestFactory().getWebtrekkParameter());
        assertEquals(0, webtrekk.getActivityCount());
        // make shure it fails when init is called twice
//        try {
//            webtrekk.initWebtrekk(getContext());
//            fail("already initalized, IllegalStateException");
//        } catch (IllegalStateException e) {
//
//        }

    }

    public void testInitTrackingConfiguration() {
        webtrekk.setContext(getContext());
        webtrekk.initTrackingConfiguration(R.raw.webtrekk_config);
        assertNotNull(webtrekk.getTrackingConfiguration());
        assertEquals(webtrekk.getTrackingConfiguration().getTrackId(), "1111111111112");
        assertEquals(webtrekk.getTrackingConfiguration().getTrackDomain(), "http://trackingtest.nglab.org");
        assertEquals(webtrekk.getTrackingConfiguration().getSendDelay(), 30);
        assertEquals(webtrekk.getTrackingConfiguration().getMaxRequests(), 4000);
        assertEquals(webtrekk.getTrackingConfiguration().getVersion(), 3);

    }
    public void testInitWebtrekkParameter() {
        // make sure the default params have valid values
        webtrekk.setContext(getContext());
        webtrekk.initTrackingConfiguration(R.raw.webtrekk_config);
        webtrekk.getRequestFactory().init(mContext, webtrekk.getTrackingConfiguration(), webtrekk);
        assertEquals(6, webtrekk.getRequestFactory().getWebtrekkParameter().size());
    }

    public void testUpdateDynamicParameter() {
        // make sure that the values which change with every request are inserted as well
        webtrekk.setContext(getContext());
        webtrekk.initTrackingConfiguration(R.raw.webtrekk_config);
        webtrekk.getRequestFactory().init(mContext, webtrekk.getTrackingConfiguration(), webtrekk);

        RequestUrlStore requestUrlStore = mock(RequestUrlStore.class);
        webtrekk.getRequestFactory().setRequestUrlStore(requestUrlStore);
        when(requestUrlStore.size()).thenReturn(55);

        //set some different default values
        webtrekk.getCustomParameter().put("screenOrientation", "stttr");
        webtrekk.getCustomParameter().put("connectionType", "offline");

        webtrekk.getRequestFactory().updateDynamicParameter();
        assertEquals(7, webtrekk.getRequestFactory().getWebtrekkParameter().size());
        assertTrue(webtrekk.getRequestFactory().getAutoCustomParameter().get("screenOrientation").matches("(portrait|landscape)"));
        String connectionType = webtrekk.getCustomParameter().get("connectionType");
        assertTrue(connectionType.equals("WIFI") || connectionType.equals("offline"));
        assertEquals("55", webtrekk.getRequestFactory().getAutoCustomParameter().get("requestUrlStoreSize"));
{'fraction_non_alphanumeric': 0.10933333333333334, 'fraction_numerical': 0.006419753086419753, 'mean_word_length': 4.055416874687968, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4445888', 'n_tokens_mistral': 2848, 'n_tokens_neox': 2798, 'n_words': 426}