<commit_before>/**
 * Copyright (c) 2016-2018 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee;

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

/**
 *
 * @author <NAME>
 *
 */
public class TestUtilities {

    static public void setField(Class clazz, Object object, String fieldName, Object newValue) throws Exception {
        Field field = clazz.getDeclaredField(fieldName);
        field.setAccessible(true);
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(object, newValue);
    }

}<commit_msg>Add test utility to invoke a private method in a class (#491)<commit_after>/**
 * Copyright (c) 2016-2018 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee;

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

/**
 * A class of helper methods for running tests.
 * 
 * @author <NAME>
 *
 */
public class TestUtilities {

    /**
     * Set the value of a private field in a class
     * 
     * @param clazz the class where the field resides
     * @param object the object where the field resides
     * @param fieldName the field name
     * @param newValue the Object to be set
     * @throws Exception
     */
    static public void setField(Class clazz, Object object, String fieldName, Object newValue) throws Exception {
        Field field = clazz.getDeclaredField(fieldName);
        field.setAccessible(true);
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(object, newValue);
    }

    /**
     * Invokes a private method
     *
     * @param clazz the class where the method resides
     * @param object the object where the method resides
     * @param methodName the method name
     * @param params an array of parameters - each parameter is the parameter class, followed by the parameter
     * @return the return object from the method
     * @throws NoSuchMethodException
     * @throws SecurityException
     * @throws IllegalAccessException
     * @throws IllegalArgumentException
     * @throws InvocationTargetException
     */
    static public Object invokeMethod(Class clazz, Object object, String methodName, Object... params)
            throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
            InvocationTargetException {
        int paramCount = params.length;
        Method method;
        Class<?>[] classArray = new Class<?>[paramCount / 2];
        Object[] paramArray = new Object[paramCount / 2];
        for (int i = 0; i < paramCount; i += 2) {
            classArray[i] = (Class) params[i];
            paramArray[i] = params[i + 1];
        }
        method = clazz.getDeclaredMethod(methodName, classArray);
        method.setAccessible(true);
        return method.invoke(object, paramArray);
    }

}
{'fraction_non_alphanumeric': 0.08965330444203684, 'fraction_numerical': 0.00866738894907909, 'mean_word_length': 3.225400457665904, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5939705', 'n_tokens_mistral': 1004, 'n_tokens_neox': 967, 'n_words': 326}