Skip to content

Commit

Permalink
[#1501] Create Unit Tests for FeedbackMcqQuestionDetailsTest.java (#1…
Browse files Browse the repository at this point in the history
…2638)

* added tests

* linting and whitespace

* fix failing unit test

* cleaning

* only include default constructor calls

* case

* localize accessibility test faults

* axe testing??

* revert

* remove comments

* update with Arrays.asList

* move assert participant type NONE to constructor

* added unit test for generateOptionsFor
  • Loading branch information
mhoualla authored Dec 4, 2023
1 parent 33bcd77 commit 8634a78
Showing 1 changed file with 102 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public void testConstructor_defaultConstructor_fieldsShouldHaveCorrectDefaultVal
assertFalse(mcqDetails.isHasAssignedWeights());
assertTrue(mcqDetails.getMcqWeights().isEmpty());
assertEquals(0.0, mcqDetails.getMcqOtherWeight());
assertEquals(FeedbackParticipantType.NONE, mcqDetails.getGenerateOptionsFor());
}

@Test
public void testSetter_generateOptionsFor_correctValue() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setGenerateOptionsFor(FeedbackParticipantType.STUDENTS);

assertEquals(FeedbackParticipantType.STUDENTS, mcqDetails.getGenerateOptionsFor());
}

@Test
Expand Down Expand Up @@ -92,7 +101,7 @@ public void testValidateQuestionDetails_duplicateMcqOptions_errorReturned() {
assertEquals(1, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_DUPLICATE_MCQ_OPTION, errors.get(0));

//duplicate cases that has trailing and leading spaces
// duplicate cases that has trailing and leading spaces
mcqDetails.setMcqChoices(Arrays.asList("choice 1", " choice 1 "));
errors = mcqDetails.validateQuestionDetails();
assertEquals(1, errors.size());
Expand Down Expand Up @@ -192,7 +201,8 @@ public void testValidateResponsesDetails_answerNotPartOfMcq_shouldReturnError()
List<String> errors = mcqDetails.validateResponsesDetails(responses, 1);

assertEquals(1, errors.size());
assertEquals(response.getAnswerString() + " " + FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_OPTION, errors.get(0));
assertEquals(response.getAnswerString() + " " + FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_OPTION,
errors.get(0));
}

@Test
Expand Down Expand Up @@ -225,4 +235,94 @@ public void testValidateResponsesDetails_noValidationError_errorListShouldBeEmpt

assertEquals(0, errors.size());
}

@Test
public void testIsQuestionDropdownEnabled_shouldReturnTrue() {
FeedbackMcqQuestionDetails feedbackQuestionDetails = new FeedbackMcqQuestionDetails();
feedbackQuestionDetails.setQuestionDropdownEnabled(true);
assertTrue(feedbackQuestionDetails.isQuestionDropdownEnabled());
}

@Test
public void testSetQuestionDropdownEnabled_shouldReturnFalse() {
FeedbackMcqQuestionDetails feedbackQuestionDetails = new FeedbackMcqQuestionDetails();
feedbackQuestionDetails.setQuestionDropdownEnabled(false);
assertFalse(feedbackQuestionDetails.isQuestionDropdownEnabled());
}

@Test
public void testValidateQuestionDetails_weightsNotEnabledButWeightListNotEmpty_errorReturned() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setMcqWeights(Arrays.asList(1.22, -1.55));
mcqDetails.setMcqChoices(Arrays.asList("choice 1", "choice 2"));
mcqDetails.setHasAssignedWeights(false);
List<String> errors = mcqDetails.validateQuestionDetails();
assertEquals(1, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_WEIGHT, errors.get(0));
}

@Test
public void testValidateQuestionDetails_weightsNotEnabledButOtherWeightNotZero_errorReturned() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setMcqOtherWeight(0.5);
mcqDetails.setHasAssignedWeights(false);

List<String> errors = mcqDetails.validateQuestionDetails();
assertEquals(FeedbackParticipantType.NONE, mcqDetails.getGenerateOptionsFor());
assertEquals(2, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_NOT_ENOUGH_CHOICES
+ FeedbackMcqQuestionDetails.MCQ_MIN_NUM_OF_CHOICES + ".", errors.get(0));
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_WEIGHT, errors.get(1));
}

@Test
public void testValidateQuestionDetails_hasAssignedWeightsOtherEnabledNonZeroWeight_errorReturned() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setHasAssignedWeights(true);
mcqDetails.setOtherEnabled(true);
mcqDetails.setMcqOtherWeight(1.5);
mcqDetails.setMcqChoices(Arrays.asList("choice 1", "choice 2"));

List<String> errors = mcqDetails.validateQuestionDetails();
assertEquals(1, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_WEIGHT, errors.get(0));
}

@Test
public void testValidateQuestionDetails_hasAssignedWeightsOtherEnabledNegativeWeight_errorReturned() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setHasAssignedWeights(true);
mcqDetails.setOtherEnabled(true);
mcqDetails.setMcqOtherWeight(-1.5);

List<String> errors = mcqDetails.validateQuestionDetails();
assertEquals(2, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_NOT_ENOUGH_CHOICES
+ FeedbackMcqQuestionDetails.MCQ_MIN_NUM_OF_CHOICES + ".", errors.get(0));
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_WEIGHT, errors.get(1));
}

@Test
public void testValidateQuestionDetails_hasAssignedWeightsNonEmptyWeights_errorReturned() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setHasAssignedWeights(true);
mcqDetails.setMcqWeights(Arrays.asList(1.5));

List<String> errors = mcqDetails.validateQuestionDetails();
assertEquals(2, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_NOT_ENOUGH_CHOICES
+ FeedbackMcqQuestionDetails.MCQ_MIN_NUM_OF_CHOICES + ".", errors.get(0));
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_WEIGHT, errors.get(1));
}

@Test
public void testValidateQuestionDetails_generateOptionsForNone_errorReturned() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setGenerateOptionsFor(FeedbackParticipantType.NONE);

List<String> errors = mcqDetails.validateQuestionDetails();
assertEquals(1, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_NOT_ENOUGH_CHOICES
+ FeedbackMcqQuestionDetails.MCQ_MIN_NUM_OF_CHOICES + ".", errors.get(0));
}
}

0 comments on commit 8634a78

Please sign in to comment.