0
메소드가 순서대로 호출되었는지 확인하는 단위 테스트를 작성하려고합니다. 나는이 같은 Mockito의 inOrder.verify()를 사용하고 있음을하려면 :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);
}
그러나, 두 번째) (확인하면 다음과 같은 오류와 함께 실패 : 나는 .executeOn(file)
.executeOn(any(File.class))
을 변경하는 경우
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 (...)
테스트 통과,하지만 같은 인수를 사용하여 메서드를 호출 할 수 있는지 확인하려면 싶습니다. 여기
내가 테스트하고있어 클래스의 :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