According to the docs, JFileChooser.getSelectedFiles()
returns a File
array (not a list of File
s). Even if it were a list, you wouldn't need to mock the list itself. You'd just use a normal list with File
objects and mock the JFileChooser
to return that list. In this case you use a File
array, though.
First create the File
array:
File[] files = { new File("f1"), new File("f2"), new File("f3") };
Then mock the JFileChooser
object:
JFileChooser fileChooser = mock(JFileChooser.class);
when(fileChooser.getSelectedFiles()).thenReturn(files);
You could then loop through the array returned by fileChooser
like this:
for (File currentFile : fileChooser.getSelectedFiles()) {
//...
}