unit testing - mocking creation of an array with powermock java -


i write test following function in java.i want mocking creation of array.

public file[] myfunc() {     file[] array = new file[2];   return array;  } 

i have wrote following test using powermock java:

@test  public void test1() {   file f1 = createmock(file.class);   file[] files = new file[]{f1};   expectnew(file[].class).andreturn(farray);   replayall();   file[] res = myclass.myfunc();   verifyall();  assertequals(f1, res[0]);  } 

it throws exception following message: org.powermock.reflect.exceptions.constructornotfoundexception: no constructor found in class java.io.file parameter types:<none>

the exception says it: attempt create file instance without specifying constructor arguments there no constructor without parameters class java.io.file. stack trace of exception tell code location of attempt. guess, file f1 = createmock(file.class);. check powermock documentation alternatives.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -