Skip to content
Snippets Groups Projects
Commit fc587eb9 authored by AnneliKlamas's avatar AnneliKlamas
Browse files

#46 fixed error handling

parent 1c4a7316
No related branches found
No related tags found
1 merge request!48feat: Add support for the template dropdowns #46
......@@ -18,17 +18,17 @@ public class QuestionValidationHandler {
}
public void validateQuestion() {
if (state.getName().isEmpty()) {
if (state.getAnswerOptions().isEmpty()) {
state.getErrors().add(QuestionErrorType.NO_ANSWER_OPTIONS_FOUND);
}
var correctAnswerCount = state.getAnswerOptions().stream().filter(Answer::isCorrect).count();
if (state.getType().equals(QuestionType.SINGLE_CHOICE) && correctAnswerCount > 1) {
state.getErrors().add(QuestionErrorType.ANSWER_OPTIONS_DONT_MATCH_TYPE);
}
else if (state.getType().equals(QuestionType.UNKNOWN)) {
if (state.getType().equals(QuestionType.UNKNOWN)) {
state.getErrors().add(QuestionErrorType.UNKNOWN_QUESTION_TYPE);
}
else if (state.getType().equals(QuestionType.REGULAR_EXPRESSION)) {
if (state.getType().equals(QuestionType.REGULAR_EXPRESSION)) {
for (var answerOption: state.getAnswerOptions()) {
try {
Pattern.compile(answerOption.getText());
......@@ -38,7 +38,7 @@ public class QuestionValidationHandler {
}
state.getWarnings().add(QuestionWarningType.REGEX_RESTRICTION);
}
else if (correctAnswerCount == 0) {
if (correctAnswerCount == 0) {
state.getErrors().add(QuestionErrorType.NO_CORRECT_ANSWER_FOUND);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment