物联网项目
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;
}
}