package org.bench4q.share.helper;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;

public class TestHelper {
	public static Object invokePrivate(Object targetObject, String methodName,
			Class<?>[] paramClasses, Object[] params) throws Exception {
		Method method = targetObject.getClass().getDeclaredMethod(methodName,
				paramClasses);
		method.setAccessible(true);
		return method.invoke(targetObject, params);
	}

	public static Object invokeStaticPrivate(Class<?> containerClass,
			String methodName, Class<?>[] paramClasses, Object[] params)
			throws Exception {
		Method method = containerClass.getDeclaredMethod(methodName,
				paramClasses);
		method.setAccessible(true);
		return method.invoke(null, params);
	}

	public static void createFileIfNotExist(File file) {
		if (file.exists()) {
			return;
		}
		File parentFile = file.getParentFile();
		if (!parentFile.exists()) {
			parentFile.mkdirs();
		}
		try {
			file.createNewFile();
		} catch (IOException e) {
		}
	}
}
