<commit_before>package org.wso2.carbon.kernel.utils;

import org.testng.Assert;
import org.testng.annotations.Test;
import org.wso2.carbon.kernel.Constants;

import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class UtilsTest {

    /* private static void set(Map<String, String> newenv) throws Exception {
         Class[] classes = Collections.class.getDeclaredClasses();
         Map<String, String> env = System.getenv();
         for (Class cl : classes) {
             if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
                 Field field = cl.getDeclaredField("m");
                 field.setAccessible(true);
                 Object obj = field.get(env);
                 Map<String, String> map = (Map<String, String>) obj;
                 map.clear();
                 map.putAll(newenv);
             }
         }
     }*/
    protected static void set(Map<String, String> newenv) {
        try {
            Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
            Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
            theEnvironmentField.setAccessible(true);
            Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
            env.putAll(newenv);
            Field theCaseInsensitiveEnvironmentField = processEnvironmentClass
                    .getDeclaredField("theCaseInsensitiveEnvironment");
            theCaseInsensitiveEnvironmentField.setAccessible(true);
            Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
            cienv.putAll(newenv);
        } catch (NoSuchFieldException e) {
            try {
                Class[] classes = Collections.class.getDeclaredClasses();
                Map<String, String> env = System.getenv();
                for (Class cl : classes) {
                    if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
                        Field field = cl.getDeclaredField("m");
                        field.setAccessible(true);
                        Object obj = field.get(env);
                        Map<String, String> map = (Map<String, String>) obj;
                        map.clear();
                        map.putAll(newenv);
                    }
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }

    public void test() throws IOException {
        ProcessBuilder pb = new ProcessBuilder();

        Process p = pb.start();


    }
    @Test public void testGetCarbonConfigHomePathNonNullSystemProperty() throws Exception {
        String carbonRepoDirPath = System.getProperty(Constants.CARBON_REPOSITORY);
        Boolean needToClearCarbonRepoDirPathAtTheEnd = false;

        if (carbonRepoDirPath == null) {
            carbonRepoDirPath = "test-carbon-repo-dir-path";
            System.setProperty(Constants.CARBON_REPOSITORY, carbonRepoDirPath);
            needToClearCarbonRepoDirPathAtTheEnd = true;
        }
        Assert.assertEquals(Utils.getCarbonConfigHome(), Paths.get(carbonRepoDirPath + "/conf"));

        if (needToClearCarbonRepoDirPathAtTheEnd) {
            System.clearProperty(Constants.CARBON_REPOSITORY);
        }
    }

    @Test public void testGetCarbonConfigHomePathNullSystemPropertyScenarioOne() throws Exception {

        String carbonRepoDirPath = System.getProperty(Constants.CARBON_REPOSITORY);
        Boolean needToSetCarbonRepoDirPathAtTheEnd = false;

        if (carbonRepoDirPath != null) {
            System.clearProperty(Constants.CARBON_REPOSITORY);
        } else {
            needToSetCarbonRepoDirPathAtTheEnd = true;
        }<commit_msg>CARBON-15564: removing unused method<commit_after>package org.wso2.carbon.kernel.utils;

import org.testng.Assert;
import org.testng.annotations.Test;
import org.wso2.carbon.kernel.Constants;

import java.lang.reflect.Field;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class UtilsTest {

    /* private static void set(Map<String, String> newenv) throws Exception {
         Class[] classes = Collections.class.getDeclaredClasses();
         Map<String, String> env = System.getenv();
         for (Class cl : classes) {
             if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
                 Field field = cl.getDeclaredField("m");
                 field.setAccessible(true);
                 Object obj = field.get(env);
                 Map<String, String> map = (Map<String, String>) obj;
                 map.clear();
                 map.putAll(newenv);
             }
         }
     }*/
    protected static void set(Map<String, String> newenv) {
        try {
            Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
            Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
            theEnvironmentField.setAccessible(true);
            Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
            env.putAll(newenv);
            Field theCaseInsensitiveEnvironmentField = processEnvironmentClass
                    .getDeclaredField("theCaseInsensitiveEnvironment");
            theCaseInsensitiveEnvironmentField.setAccessible(true);
            Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
            cienv.putAll(newenv);
        } catch (NoSuchFieldException e) {
            try {
                Class[] classes = Collections.class.getDeclaredClasses();
                Map<String, String> env = System.getenv();
                for (Class cl : classes) {
                    if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
                        Field field = cl.getDeclaredField("m");
                        field.setAccessible(true);
                        Object obj = field.get(env);
                        Map<String, String> map = (Map<String, String>) obj;
                        map.clear();
                        map.putAll(newenv);
                    }
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }

    @Test public void testGetCarbonConfigHomePathNonNullSystemProperty() throws Exception {
        String carbonRepoDirPath = System.getProperty(Constants.CARBON_REPOSITORY);
        Boolean needToClearCarbonRepoDirPathAtTheEnd = false;

        if (carbonRepoDirPath == null) {
            carbonRepoDirPath = "test-carbon-repo-dir-path";
            System.setProperty(Constants.CARBON_REPOSITORY, carbonRepoDirPath);
            needToClearCarbonRepoDirPathAtTheEnd = true;
        }
        Assert.assertEquals(Utils.getCarbonConfigHome(), Paths.get(carbonRepoDirPath + "/conf"));

        if (needToClearCarbonRepoDirPathAtTheEnd) {
            System.clearProperty(Constants.CARBON_REPOSITORY);
        }
    }

    @Test public void testGetCarbonConfigHomePathNullSystemPropertyScenarioOne() throws Exception {

        String carbonRepoDirPath = System.getProperty(Constants.CARBON_REPOSITORY);
        Boolean needToSetCarbonRepoDirPathAtTheEnd = false;

        if (carbonRepoDirPath != null) {
            System.clearProperty(Constants.CARBON_REPOSITORY);
        } else {
            needToSetCarbonRepoDirPathAtTheEnd = true;
        }
{'fraction_non_alphanumeric': 0.09872897676210039, 'fraction_numerical': 0.0021825651559892155, 'mean_word_length': 2.271734565308694, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '1461845', 'n_tokens_mistral': 2069, 'n_tokens_neox': 2043, 'n_words': 371}