public void testCreateCourse() throws Exception {

    /*Explanation:
     * The SUT (i.e. CoursesLogic::createCourse) has only 1 path. Therefore, we
     * should typically have 1 test cases here.
     */
    ______TS("typical case");

    CourseAttributes c = new CourseAttributes();
    c.id = "Computing101-fresh";
    c.name = "Basic Computing";
    coursesLogic.createCourse(c.id, c.name);
    TestHelper.verifyPresentInDatastore(c);
    coursesLogic.deleteCourseCascade(c.id);
    ______TS("Null parameter");

    try {
      coursesLogic.createCourse(null, c.name);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Non-null value expected", e.getMessage());
    }
  }
  public void testDeleteCourse() throws Exception {

    ______TS("typical case");

    CourseAttributes course1OfInstructor = dataBundle.courses.get("typicalCourse1");
    StudentAttributes studentInCourse = dataBundle.students.get("student1InCourse1");

    // Ensure there are entities in the datastore under this course
    assertTrue(StudentsLogic.inst().getStudentsForCourse(course1OfInstructor.id).size() != 0);

    TestHelper.verifyPresentInDatastore(course1OfInstructor);
    TestHelper.verifyPresentInDatastore(studentInCourse);
    TestHelper.verifyPresentInDatastore(dataBundle.evaluations.get("evaluation1InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.evaluations.get("evaluation2InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.instructors.get("instructor1OfCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.instructors.get("instructor3OfCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.students.get("student1InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.students.get("student5InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.feedbackSessions.get("session1InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.feedbackSessions.get("session2InCourse1"));
    assertEquals(course1OfInstructor.id, studentInCourse.course);

    coursesLogic.deleteCourseCascade(course1OfInstructor.id);

    // Ensure the course and related entities are deleted
    TestHelper.verifyAbsentInDatastore(course1OfInstructor);
    TestHelper.verifyAbsentInDatastore(studentInCourse);
    TestHelper.verifyAbsentInDatastore(dataBundle.evaluations.get("evaluation1InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.evaluations.get("evaluation2InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.instructors.get("instructor1OfCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.instructors.get("instructor3OfCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.students.get("student1InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.students.get("student5InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.feedbackSessions.get("session1InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.feedbackSessions.get("session2InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.comments.get("comment1FromI1C1toS1C1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.comments.get("comment2FromI1C1toS1C1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.comments.get("comment1FromI3C1toS2C1"));

    ArrayList<SubmissionAttributes> submissionsOfCourse =
        new ArrayList<SubmissionAttributes>(dataBundle.submissions.values());
    for (SubmissionAttributes s : submissionsOfCourse) {
      if (s.course.equals(course1OfInstructor.id)) {
        TestHelper.verifyAbsentInDatastore(s);
      }
    }

    ______TS("non-existent");

    // try to delete again. Should fail silently.
    coursesLogic.deleteCourseCascade(course1OfInstructor.id);

    ______TS("null parameter");

    try {
      coursesLogic.deleteCourseCascade(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
  public void testCreateCourseAndInstructor() throws Exception {

    /* Explanation: SUT has 5 paths. They are,
     * path 1 - exit because the account doesn't' exist.
     * path 2 - exit because the account exists but doesn't have instructor privileges.
     * path 3 - exit because course creation failed.
     * path 4 - exit because instructor creation failed.
     * path 5 - success.
     * Accordingly, we have 5 test cases.
     */

    ______TS("fails: account doesn't exist");

    CourseAttributes c = new CourseAttributes();
    c.id = "fresh-course-tccai";
    c.name = "Fresh course for tccai";

    @SuppressWarnings("deprecation")
    InstructorAttributes i =
        new InstructorAttributes(
            "instructor-for-tccai", c.id, "Instructor for tccai", "*****@*****.**");

    try {
      coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      AssertHelper.assertContains("for a non-existent instructor", e.getMessage());
    }
    TestHelper.verifyAbsentInDatastore(c);
    TestHelper.verifyAbsentInDatastore(i);

    ______TS("fails: account doesn't have instructor privileges");

    AccountAttributes a = new AccountAttributes();
    a.googleId = i.googleId;
    a.name = i.name;
    a.email = i.email;
    a.institute = "TEAMMATES Test Institute 5";
    a.isInstructor = false;
    a.studentProfile = new StudentProfileAttributes();
    a.studentProfile.googleId = i.googleId;
    accountsDb.createAccount(a);
    try {
      coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      AssertHelper.assertContains("doesn't have instructor privileges", e.getMessage());
    }
    TestHelper.verifyAbsentInDatastore(c);
    TestHelper.verifyAbsentInDatastore(i);

    ______TS("fails: error during course creation");

    a.isInstructor = true;
    accountsDb.updateAccount(a);

    c.id = "invalid id";

    try {
      coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name);
      signalFailureToDetectException();
    } catch (InvalidParametersException e) {
      AssertHelper.assertContains("not acceptable to TEAMMATES as a Course ID", e.getMessage());
    }
    TestHelper.verifyAbsentInDatastore(c);
    TestHelper.verifyAbsentInDatastore(i);

    ______TS("fails: error during instructor creation due to duplicate instructor");

    c.id = "fresh-course-tccai";
    instructorsDb.createEntity(i); // create a duplicate instructor

    try {
      coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      AssertHelper.assertContains(
          "Unexpected exception while trying to create instructor for a new course",
          e.getMessage());
    }
    TestHelper.verifyAbsentInDatastore(c);

    ______TS("fails: error during instructor creation due to invalid parameters");

    i.email = "ins.for.iccai.gmail.tmt";

    try {
      coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      AssertHelper.assertContains(
          "Unexpected exception while trying to create instructor for a new course",
          e.getMessage());
    }
    TestHelper.verifyAbsentInDatastore(c);

    ______TS("success: typical case");

    i.email = "*****@*****.**";

    // remove the duplicate instructor object from the datastore.
    instructorsDb.deleteInstructor(i.courseId, i.email);

    coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name);
    TestHelper.verifyPresentInDatastore(c);
    TestHelper.verifyPresentInDatastore(i);

    ______TS("Null parameter");

    try {
      coursesLogic.createCourseAndInstructor(null, c.id, c.name);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }