<commit_before>/*
 * Certain versions of software and/or documents ("Material") accessible here may contain branding from
 * Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company.  As of September 1, 2017,
 * the Material is now offered by Micro Focus, a separately owned and operated company.  Any reference to the HP
 * and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE
 * marks are the property of their respective owners.
 * __________________________________________________________________
 * MIT License
 *
 * (c) Copyright 2012-2018 Micro Focus or one of its affiliates.
 *
 * The only warranties for products and services of Micro Focus and its affiliates
 * and licensors ("Micro Focus") are set forth in the express warranty statements
 * accompanying such products and services. Nothing herein should be construed as
 * constituting an additional warranty. Micro Focus shall not be liable for technical
 * or editorial errors or omissions contained herein.
 * The information contained herein is subject to change without notice.
 * ___________________________________________________________________
 */

package com.microfocus.application.automation.tools.common;

import org.junit.*;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class OperatingSystemTest {
    private static String os;
    public static void initializeOperatingSystemOs(final String os) throws NoSuchFieldException, IllegalAccessException {
        changeStaticFinalField(os, "OS");

        if (os.toLowerCase().contains("windows")) {
            changeBooleanStaticFinalField(true, "IS_WINDOWS");
            changeBooleanStaticFinalField(false, "IS_MAC");
            changeBooleanStaticFinalField(false, "IS_LINUX");
        } else if (os.toLowerCase().contains("linux")) {
            changeBooleanStaticFinalField(false, "IS_WINDOWS");
            changeBooleanStaticFinalField(false, "IS_MAC");
            changeBooleanStaticFinalField(true, "IS_LINUX");
        } else if (os.toLowerCase().contains("mac")) {
            changeBooleanStaticFinalField(false, "IS_WINDOWS");
            changeBooleanStaticFinalField(true, "IS_MAC");
            changeBooleanStaticFinalField(false, "IS_LINUX");
        }
    }

    private static void changeStaticFinalField(String value, String declaredField)
            throws NoSuchFieldException, IllegalAccessException {
        Field field = OperatingSystem.class.getDeclaredField(declaredField);
        field.setAccessible(true);
        Field modifiers = Field.class.getDeclaredField("modifiers");
        modifiers.setAccessible(true);
        modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, value.toLowerCase());
    }

    private static void changeBooleanStaticFinalField(boolean value, String declaredField)
            throws NoSuchFieldException, IllegalAccessException {
        Field field = OperatingSystem.class.getDeclaredField(declaredField);
        field.setAccessible(true);
        Field modifiers = Field.class.getDeclaredField("modifiers");
        modifiers.setAccessible(true);
        modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, value);
    }

    @BeforeClass
    public static void setup() throws Exception {
        os = System.getProperty("os.name");
    }


    @AfterClass
    public static void tearDown() throws Exception {
        initializeOperatingSystemOs(os);
    }
<commit_msg>JENKINS-53930: Fix flake test with OperatingSystem<commit_after>/*
 * Certain versions of software and/or documents ("Material") accessible here may contain branding from
 * Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company.  As of September 1, 2017,
 * the Material is now offered by Micro Focus, a separately owned and operated company.  Any reference to the HP
 * and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE
 * marks are the property of their respective owners.
 * __________________________________________________________________
 * MIT License
 *
 * (c) Copyright 2012-2018 Micro Focus or one of its affiliates.
 *
 * The only warranties for products and services of Micro Focus and its affiliates
 * and licensors ("Micro Focus") are set forth in the express warranty statements
 * accompanying such products and services. Nothing herein should be construed as
 * constituting an additional warranty. Micro Focus shall not be liable for technical
 * or editorial errors or omissions contained herein.
 * The information contained herein is subject to change without notice.
 * ___________________________________________________________________
 */

package com.microfocus.application.automation.tools.common;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class OperatingSystemTest {
    private static String os;

    public static void initializeOperatingSystemOs(final String os) throws NoSuchFieldException, IllegalAccessException {
        changeStaticFinalField(os, "OS");

        if (os.toLowerCase().contains("windows")) {
            setAllBooleanStaticFinalFields(true, false, false);
        } else if (os.toLowerCase().contains("linux")) {
            setAllBooleanStaticFinalFields(false, false, true);
        } else if (os.toLowerCase().contains("mac")) {
            setAllBooleanStaticFinalFields(false, true, false);
        } else {
            setAllBooleanStaticFinalFields(false, false, false);
        }
    }

    private static void setAllBooleanStaticFinalFields(boolean isWindows, boolean isMac, boolean isLinux)
            throws NoSuchFieldException, IllegalAccessException {
        changeBooleanStaticFinalField(isWindows, "IS_WINDOWS");
        changeBooleanStaticFinalField(isMac, "IS_MAC");
        changeBooleanStaticFinalField(isLinux, "IS_LINUX");
    }

    private static void changeStaticFinalField(String value, String declaredField)
            throws NoSuchFieldException, IllegalAccessException {
        Field field = OperatingSystem.class.getDeclaredField(declaredField);
        field.setAccessible(true);
        Field modifiers = Field.class.getDeclaredField("modifiers");
        modifiers.setAccessible(true);
        modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, value.toLowerCase());
    }

    private static void changeBooleanStaticFinalField(boolean value, String declaredField)
            throws NoSuchFieldException, IllegalAccessException {
        Field field = OperatingSystem.class.getDeclaredField(declaredField);
        field.setAccessible(true);
        Field modifiers = Field.class.getDeclaredField("modifiers");
        modifiers.setAccessible(true);
        modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, value);
    }

    @BeforeClass
    public static void setup() {
        os = System.getProperty("os.name");
    }


    @AfterClass
    public static void tearDown() throws Exception {
        initializeOperatingSystemOs(os);
    }

{'fraction_non_alphanumeric': 0.07919297282459511, 'fraction_numerical': 0.0042547351084271205, 'mean_word_length': 3.8840482573726542, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5330001', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1747, 'n_words': 550}