Exemplo n.º 1
0
  @Test
  public void allTests() {

    ______TS("No students");

    CourseRoster roster = new CourseRoster(null, null);
    assertFalse(roster.isStudentInCourse("studentEmail"));

    ______TS("only 1 student, no instructors");

    roster = new CourseRoster(createStudentList("team 1", "*****@*****.**"), null);
    assertFalse(roster.isStudentInCourse("*****@*****.**"));
    assertTrue(roster.isStudentInCourse("*****@*****.**"));

    assertFalse(roster.isStudentInTeam("*****@*****.**", "team 1"));
    assertFalse(roster.isStudentInTeam("*****@*****.**", "team 123"));
    assertTrue(roster.isStudentInTeam("*****@*****.**", "team 1"));

    assertFalse(roster.isStudentsInSameTeam("*****@*****.**", "*****@*****.**"));
    assertFalse(roster.isStudentsInSameTeam("*****@*****.**", "*****@*****.**"));
    assertTrue(roster.isStudentsInSameTeam("*****@*****.**", "*****@*****.**"));

    assertEquals(roster.getStudentForEmail("*****@*****.**").email, "*****@*****.**");
    assertEquals(roster.getStudentForEmail("*****@*****.**").team, "team 1");
    assertEquals(roster.getInstructorForEmail("*****@*****.**"), null);

    ______TS("only 1 instructor, no students");

    roster = new CourseRoster(null, createInstructorList("John", "*****@*****.**"));
    assertEquals(roster.getInstructorForEmail("*****@*****.**").email, "*****@*****.**");
    assertEquals(roster.getInstructorForEmail("*****@*****.**").name, "John");

    assertEquals(roster.getInstructorForEmail("*****@*****.**"), null);

    ______TS("multiple students, multiple instructors");

    roster =
        new CourseRoster(
            createStudentList(
                "team 1", "*****@*****.**", "team 1", "*****@*****.**", "team 2", "*****@*****.**"),
            createInstructorList("John", "*****@*****.**", "Jean", "*****@*****.**"));

    assertFalse(roster.isStudentInCourse("*****@*****.**"));
    assertTrue(roster.isStudentInCourse("*****@*****.**"));

    assertFalse(roster.isStudentInTeam("*****@*****.**", "team 1"));
    assertFalse(roster.isStudentInTeam("*****@*****.**", "team 1"));
    assertTrue(roster.isStudentInTeam("*****@*****.**", "team 1"));
    assertTrue(roster.isStudentInTeam("*****@*****.**", "team 1"));
    assertTrue(roster.isStudentInTeam("*****@*****.**", "team 2"));

    assertFalse(roster.isStudentsInSameTeam("*****@*****.**", "*****@*****.**"));
    assertFalse(roster.isStudentsInSameTeam("*****@*****.**", "*****@*****.**"));
    assertTrue(roster.isStudentsInSameTeam("*****@*****.**", "*****@*****.**"));

    assertEquals(roster.getInstructorForEmail("*****@*****.**").email, "*****@*****.**");
    assertEquals(roster.getInstructorForEmail("*****@*****.**").name, "John");
    assertEquals(roster.getInstructorForEmail("*****@*****.**").email, "*****@*****.**");
    assertEquals(roster.getInstructorForEmail("*****@*****.**").name, "Jean");
  }
Exemplo n.º 2
0
  public boolean isNameVisibleTo(
      FeedbackQuestionAttributes question,
      FeedbackResponseAttributes response,
      String userEmail,
      UserType.Role role,
      boolean isGiverName,
      CourseRoster roster) {

    if (question == null) {
      return false;
    }

    List<FeedbackParticipantType> showNameTo =
        isGiverName ? question.showGiverNameTo : question.showRecipientNameTo;

    // Giver can always see giver and recipient.(because he answered.)
    if (response.giverEmail.equals(userEmail)) {
      return true;
    }

    for (FeedbackParticipantType type : showNameTo) {
      switch (type) {
        case INSTRUCTORS:
          if (roster.getInstructorForEmail(userEmail) != null && role == UserType.Role.INSTRUCTOR) {
            return true;
          } else {
            break;
          }
        case OWN_TEAM_MEMBERS:
        case OWN_TEAM_MEMBERS_INCLUDING_SELF:
          // Refers to Giver's Team Members
          if (roster.isStudentsInSameTeam(response.giverEmail, userEmail)) {
            return true;
          } else {
            break;
          }
        case RECEIVER:
          // Response to team
          if (question.recipientType == FeedbackParticipantType.TEAMS) {
            if (roster.isStudentInTeam(
                userEmail, /* this is a team name */ response.recipientEmail)) {
              return true;
            }
            // Response to individual
          } else if (response.recipientEmail.equals(userEmail)) {
            return true;
          } else {
            break;
          }
        case RECEIVER_TEAM_MEMBERS:
          // Response to team; recipient = teamName
          if (question.recipientType == FeedbackParticipantType.TEAMS) {
            if (roster.isStudentInTeam(
                userEmail, /* this is a team name */ response.recipientEmail)) {
              return true;
            }
            // Response to individual
          } else if (roster.isStudentsInSameTeam(response.recipientEmail, userEmail)) {
            return true;
          } else {
            break;
          }
        case STUDENTS:
          if (roster.isStudentInCourse(userEmail)) {
            return true;
          } else {
            break;
          }
        default:
          Assumption.fail(
              "Invalid FeedbackPariticipantType for showNameTo in "
                  + "FeedbackResponseLogic.isNameVisible()");
          break;
      }
    }
    return false;
  }