I am using JUnit4 and I am trying to set up a test that can be used for multiple classes that are identical(not important why they all are), but I am passing in multiple java files to the test and from that i am trying to create objects that have both the .class and the name of a method in the method eg. list.add(new Object[]{testClass.class, testClass.class.methodName()});
It works fine if you enter the name of the .class and the name of the method exactly as is(as in the example above) but as I want to do this for a number of different classes I need to pass them in in a loop and i am using the following code list.add(new Object[]{currentFile.getClass(), currentFile.getClass().getMethod(addTwoNumbers,int, int)}
where currentFile
is the current file being processed and .getMethod(addTwoNumbers,int, int)
addTwoNumbers is the name of the method which takes two ints eg. addTwoNumbers(int one, int two)
but I am getting the following error
'.class' expected
'.class' expected
unexpected type
required: value
found: class
unexpected type
required: value
found: class
Here is my full code
CompilerForm compilerForm = new CompilerForm();
RetrieveFiles retrieveFiles = new RetrieveFiles();
@RunWith(Parameterized.class)
public class BehaviorTest {
@Parameters
public Collection<Object[]> classesAndMethods() throws NoSuchMethodException {
List<Object[]> list = new ArrayList<>();
List<File> files = new ArrayList<>();
final File folder = new File(compilerForm.getPathOfFileFromNode());
files = retrieveFiles.listFilesForFolder(folder);
for(File currentFile: files){
list.add(new Object[]{currentFile.getClass(), currentFile.getClass().getMethod(addTwoNumbers,int, int)});
}
return list;
}
private Class clazz;
private Method method;
public BehaviorTest(Class clazz, Method method) {
this.clazz = clazz;
this.method = method;
}
Does anyone see what I am doing wrong with this line list.add(new Object[]{currentFile.getClass(), currentFile.getClass().getMethod(addTwoNumbers,int, int)});
}
?