Я хочу протестировать метод процесса класса ProcessServiceImpl
с насмешливыми частными методами: классы readContent
и isValidFile
и userService
.
@Named("processServiceImpl")
public class ProcessServiceImpl {
@Inject
private UserService userService;
public User process(Long userId, File inputFile) throws InvalidFileException {
User user = userService.load(userId);
String fileContent = readContent(inputFile);
if (isValidFile(fileContent)) {
User updatedUser = userService.updateUser(user, fileContent);
return updatedUser;
} else {
throw new InvalidFileException();
}
}
private String readContent(File inputFile) {
//implementation
}
private boolean isValidFile(String fileContent) {
//implementation
}
}
Я смоделировал UserService
и успешно ввел его. но я не могу издеваться над частными методами тестируемого класса. На основе этого и эти ссылки, я пытался издеваться над ними с помощью NonStrictExpectations
, но он не любой invoke
метод!! Есть ли другой способ сделать это? (Я использую jmockit-1.8)
new NonStrictExpectations(processServiceImpl) {{
invoke(processServiceImpl, "readContent");
result = "";
}};