Я пытаюсь написать модульный тест, который проверяет, были ли методы вызваны в порядке. Для этого я использую inOrder.verify Mockito в(), как это:Mockito inOrder.verify() не работает с использованием mock как аргумент функции
@Test
public void shouldExecuteAllFileCommandsOnAFileInFIFOOrder() {
// Given
ProcessFileListCommand command = new ProcessFileListCommand();
FileCommand fileCommand1 = mock(FileCommand.class, "fileCommand1");
command.addCommand(fileCommand1);
FileCommand fileCommand2 = mock(FileCommand.class, "fileCommand2");
command.addCommand(fileCommand2);
File file = mock(File.class, "file");
File[] fileArray = new File[] { file };
// When
command.executeOn(fileArray);
// Then
InOrder inOrder = Mockito.inOrder(fileCommand1, fileCommand2);
inOrder.verify(fileCommand1).executeOn(file);
inOrder.verify(fileCommand2).executeOn(file);
}
Однако второй проверить() не со следующей ошибкой:
org.mockito.exceptions.verification.VerificationInOrderFailure:
Verification in order failure
Wanted but not invoked:
fileCommand2.executeOn(file);
-> at (...)
Wanted anywhere AFTER following interaction:
fileCommand1.executeOn(file);
-> at (...)
Если изменить .executeOn(file)
к .executeOn(any(File.class))
в тестовые проходы, но я хочу убедиться, что методы вызываются с использованием того же аргумента.
Вот класс я тестирую:
public class ProcessFileListCommand implements FileListCommand {
private List<FileCommand> commands = new ArrayList<FileCommand>();
public void addCommand(final FileCommand command) {
this.commands.add(command);
}
@Override
public void executeOn(final File[] files) {
for (File file : files) {
for (FileCommand command : commands) {
file = command.executeOn(file);
}
}
}
}
Спасибо, я не могу поверить, что пропустил этот: D – Obszczymucha