ユビキタスネットワークプロジェクト

1351 ワード

1.JUnitテスト、プライベートクラスのテスト
package com.message.service;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

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

import org.junit.Test;

public class BaseTestCase {
protected Object invokeUnPublicMethod(Object pInstance, String pMethodName, Class[] paramTypes, Object[] parmValues) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException{
Object result = null;
//MessageHandler h = new MessageHandler();
Method m = pInstance.getClass().getDeclaredMethod(pMethodName, paramTypes);
m.setAccessible(true);

result = m.invoke(pInstance,parmValues);
m.setAccessible(false);
System.out.println(result);
return result;
}
}