J
jimgardener
hi
i am trying out PrivilegedAccessor class (of http://sourceforge.net/projects/privaccessor/)
along with junit to test some private methods that process double[]
[] .I think this uses reflection to access private methods
public class MyClass {
private double[] processArray(double[] inarray){
double[] ret=new double[inarray.length];
for(int i=0;i<inarray.length;i++){
ret=inarray+100.0;
}
return ret;
}
}
here is the testcase class
<code>
import junit.framework.TestCase;
import junit.extensions.PrivilegedAccessor;
public class MyClassTest extends TestCase{
public MyClassTest(String name){
super(name);
}
public void testMyClass()throws Exception{
MyClass mc=new MyClass();
assertNotNull(mc);
double[] inputarray=new double[]{1.1,2.2,3.3,4.4};
double[] ans=new double[]{101.1,102.2,103.3,104.4};
double[] outputarray=(double[])
(PrivilegedAccessor.invokeMethod(mc,"processArray(double[])",inputarray));
assertEquals(outputarray,ans);
}
}
<code>
when i run the test ,i get an error message like
java.lang.NoSuchMethodException: Method 'processArray(double[])'s
parameter nr1 (double[]) not found
This error originates at the call PrivilegedAccessor.invokeMethod(..)
can someone tell me why this happens?
thanks
jim
i am trying out PrivilegedAccessor class (of http://sourceforge.net/projects/privaccessor/)
along with junit to test some private methods that process double[]
[] .I think this uses reflection to access private methods
public class MyClass {
private double[] processArray(double[] inarray){
double[] ret=new double[inarray.length];
for(int i=0;i<inarray.length;i++){
ret=inarray+100.0;
}
return ret;
}
}
here is the testcase class
<code>
import junit.framework.TestCase;
import junit.extensions.PrivilegedAccessor;
public class MyClassTest extends TestCase{
public MyClassTest(String name){
super(name);
}
public void testMyClass()throws Exception{
MyClass mc=new MyClass();
assertNotNull(mc);
double[] inputarray=new double[]{1.1,2.2,3.3,4.4};
double[] ans=new double[]{101.1,102.2,103.3,104.4};
double[] outputarray=(double[])
(PrivilegedAccessor.invokeMethod(mc,"processArray(double[])",inputarray));
assertEquals(outputarray,ans);
}
}
<code>
when i run the test ,i get an error message like
java.lang.NoSuchMethodException: Method 'processArray(double[])'s
parameter nr1 (double[]) not found
This error originates at the call PrivilegedAccessor.invokeMethod(..)
can someone tell me why this happens?
thanks
jim