Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12641] Adding coverage to the isResponseOfFeedbackQuestionVisibleToStudent method #12641

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 125 additions & 6 deletions src/test/java/teammates/logic/core/FeedbackResponsesLogicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import teammates.common.exception.EntityDoesNotExistException;
import teammates.test.AssertHelper;

import static teammates.common.datatransfer.FeedbackParticipantType.*;

/**
* SUT: {@link FeedbackResponsesLogic}.
*/
Expand Down Expand Up @@ -523,12 +525,12 @@ public void testIsNameVisibleTo() {

fq.setRecipientType(FeedbackParticipantType.TEAMS);
fq.getShowRecipientNameTo().clear();
fq.getShowRecipientNameTo().add(FeedbackParticipantType.RECEIVER);
fq.getShowRecipientNameTo().add(RECEIVER);
fr.setRecipient(student.getTeam());
assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.getEmail(), false, false, roster));
assertTrue(frLogic.isNameVisibleToUser(fq, fr, student3.getEmail(), false, false, roster));

fq.setRecipientType(FeedbackParticipantType.STUDENTS);
fq.setRecipientType(STUDENTS);
fr.setRecipient(student.getEmail());
assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.getEmail(), false, false, roster));
assertFalse(frLogic.isNameVisibleToUser(fq, fr, student2.getEmail(), false, false, roster));
Expand All @@ -540,7 +542,7 @@ public void testIsNameVisibleTo() {
assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.getEmail(), false, false, roster));
assertTrue(frLogic.isNameVisibleToUser(fq, fr, student3.getEmail(), false, false, roster));

fq.setRecipientType(FeedbackParticipantType.STUDENTS);
fq.setRecipientType(STUDENTS);
fr.setRecipient(student.getEmail());
assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.getEmail(), false, false, roster));
assertTrue(frLogic.isNameVisibleToUser(fq, fr, student3.getEmail(), false, false, roster));
Expand All @@ -565,8 +567,8 @@ public void testIsNameVisibleTo() {
// Only members of the recipient team should be able to see the recipient name
fq.setRecipientType(FeedbackParticipantType.TEAMS);
fq.getShowRecipientNameTo().clear();
fq.getShowRecipientNameTo().add(FeedbackParticipantType.RECEIVER);
fq.getShowResponsesTo().add(FeedbackParticipantType.STUDENTS);
fq.getShowRecipientNameTo().add(RECEIVER);
fq.getShowResponsesTo().add(STUDENTS);
fr.setRecipient("Team 1.1");
assertFalse(frLogic.isNameVisibleToUser(fq, fr, student5.getEmail(), false, false, roster));

Expand Down Expand Up @@ -1076,7 +1078,7 @@ public void testDeleteFeedbackResponsesInvolvedEntityOfCourseCascade_giverIsStud
FeedbackResponseAttributes fra = getResponseFromDatabase("response3ForQ2S1C1");
StudentAttributes student2InCourse1 = dataBundle.students.get("student2InCourse1");
// giver is student
assertEquals(FeedbackParticipantType.STUDENTS,
assertEquals(STUDENTS,
fqLogic.getFeedbackQuestion(fra.getFeedbackQuestionId()).getGiverType());
// student is the recipient
assertEquals(fra.getRecipient(), student2InCourse1.getEmail());
Expand Down Expand Up @@ -1712,6 +1714,123 @@ public void testGetSessionResultsForUser_orphanResponseInDB_shouldStillHandleCor
assertEquals(4, responseForQuestion.size());
}

@Test
public void testIsResponseOfFeedbackQuestionVisibleToStudentCT1(){

List<FeedbackParticipantType> showResponseTo = new ArrayList<>();
showResponseTo.add(STUDENTS);

FeedbackQuestionAttributes question = FeedbackQuestionAttributes.builder()
.withShowResponsesTo(showResponseTo)
.build();
boolean response = FeedbackResponsesLogic.inst().isResponseOfFeedbackQuestionVisibleToStudent(question);
assertEquals(response, true);
}

@Test
public void testIsResponseOfFeedbackQuestionVisibleToStudentCT2(){

List<FeedbackParticipantType> showResponseTo = new ArrayList<>();
showResponseTo.add(RECEIVER);

FeedbackQuestionAttributes question = FeedbackQuestionAttributes.builder()
.withShowResponsesTo(showResponseTo)
.withRecipientType(FeedbackParticipantType.STUDENTS)
.withGiverType(STUDENTS)
.build();
boolean response = FeedbackResponsesLogic.inst().isResponseOfFeedbackQuestionVisibleToStudent(question);
assertEquals(response, true);
}

@Test
public void testIsResponseOfFeedbackQuestionVisibleToStudentCT3(){

List<FeedbackParticipantType> showResponseTo = new ArrayList<>();
showResponseTo.add(RECEIVER);

FeedbackQuestionAttributes question = FeedbackQuestionAttributes.builder()
.withShowResponsesTo(showResponseTo)
.withRecipientType(FeedbackParticipantType.STUDENTS_EXCLUDING_SELF)
.withGiverType(STUDENTS)
.build();
boolean response = FeedbackResponsesLogic.inst().isResponseOfFeedbackQuestionVisibleToStudent(question);
assertEquals(response, true);
}

@Test
public void testIsResponseOfFeedbackQuestionVisibleToStudentCT4(){

List<FeedbackParticipantType> showResponseTo = new ArrayList<>();
showResponseTo.add(RECEIVER);

FeedbackQuestionAttributes question = FeedbackQuestionAttributes.builder()
.withShowResponsesTo(showResponseTo)
.withRecipientType(FeedbackParticipantType.STUDENTS_IN_SAME_SECTION)
.withGiverType(STUDENTS)
.build();
boolean response = FeedbackResponsesLogic.inst().isResponseOfFeedbackQuestionVisibleToStudent(question);
assertEquals(response, true);
}

@Test
public void testIsResponseOfFeedbackQuestionVisibleToStudentCT5(){

List<FeedbackParticipantType> showResponseTo = new ArrayList<>();
showResponseTo.add(RECEIVER);

FeedbackQuestionAttributes question = FeedbackQuestionAttributes.builder()
.withShowResponsesTo(showResponseTo)
.withRecipientType(FeedbackParticipantType.OWN_TEAM_MEMBERS)
.withGiverType(STUDENTS)
.build();
boolean response = FeedbackResponsesLogic.inst().isResponseOfFeedbackQuestionVisibleToStudent(question);
assertEquals(response, true);
}
@Test
public void testIsResponseOfFeedbackQuestionVisibleToStudentCT6(){

List<FeedbackParticipantType> showResponseTo = new ArrayList<>();
showResponseTo.add(RECEIVER);

FeedbackQuestionAttributes question = FeedbackQuestionAttributes.builder()
.withShowResponsesTo(showResponseTo)
.withRecipientType(FeedbackParticipantType.GIVER)
.withGiverType(STUDENTS)
.build();
boolean response = FeedbackResponsesLogic.inst().isResponseOfFeedbackQuestionVisibleToStudent(question);
assertEquals(response, true);
}

@Test
public void testIsResponseOfFeedbackQuestionVisibleToStudentCT7(){

List<FeedbackParticipantType> showResponseTo = new ArrayList<>();
showResponseTo.add(RECEIVER_TEAM_MEMBERS);

FeedbackQuestionAttributes question = FeedbackQuestionAttributes.builder()
.withShowResponsesTo(showResponseTo)
.withRecipientType(NONE)
.withGiverType(NONE)
.build();
boolean response = FeedbackResponsesLogic.inst().isResponseOfFeedbackQuestionVisibleToStudent(question);
assertEquals(response, false);
}

@Test
public void testIsResponseOfFeedbackQuestionVisibleToStudentCT8(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's rename the test cases to be more descriptive as well, following the convention testIsResponseOfFeedbackQuestionVisibleToStudent__, an example is above on line 1687 testGetSessionResultsForUser_orphanResponseInDB_shouldStillHandleCorrectly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected test case descriptions


List<FeedbackParticipantType> showResponseTo = new ArrayList<>();
showResponseTo.add(OWN_TEAM_MEMBERS);

FeedbackQuestionAttributes question = FeedbackQuestionAttributes.builder()
.withShowResponsesTo(showResponseTo)
.withRecipientType(NONE)
.withGiverType(TEAMS)
.build();
boolean response = FeedbackResponsesLogic.inst().isResponseOfFeedbackQuestionVisibleToStudent(question);
assertEquals(response, true);
}

private FeedbackQuestionAttributes getQuestionFromDatabase(DataBundle dataBundle, String jsonId) {
FeedbackQuestionAttributes questionToGet = dataBundle.feedbackQuestions.get(jsonId);
questionToGet = fqLogic.getFeedbackQuestion(questionToGet.getFeedbackSessionName(),
Expand Down
Loading