I have a class FileGenerator, and I'm writing a test for the generateFile() method that should do the following:
1) it should call the static method getBlockImpl(FileTypeEnum) on BlockAbstractFactory
2) it should populate variable blockList from the subclass method getBlocks()
3) it should call a static method createFile from a final helper class FileHelper passing a String parameter
4) it should call the run method of each BlockController in the blockList
I'm trying to use TDD to test the last scenario of my method. I have a list of BlockController objects that implement Runnable, and I need to verify if each one calls the run() method.
Here's what I'm trying to do:
public class FileGenerator {
// private fields with Getters and Setters
public void generateBlocks() {
// 1,2 get the block manager that will return the BlockController list
blockManager = BlockAbstractFactory.getManager(fileType);
blockList = blockManager.getBlocks();
// create a file using FileHelper
FileHelper.createFile(path);
// What I want to test:
// for each BlockController in the blockList, call the run() method
}
}
I am using Junit and Mockito. In the Mockito's documentation, they only show how to mock a List and verify method calls on the List (such as add(T), remove(T) etc), not its objects.
Any idea how I can do this?