@Test
  public void testSanitizeForSaving() {
    EvaluationAttributes e = generateValidEvaluationAttributesObject();
    EvaluationAttributes original = e.getCopy();

    // make it unsanitized
    e.courseId = "  " + e.courseId + "   ";
    e.name = "\t " + e.name + "  \t";
    e.instructions = new Text("   " + e.instructions.getValue() + "\n\t  ");

    e.sanitizeForSaving();

    assertEquals(original.toString(), e.toString());
  }
  public static EvaluationAttributes generateValidEvaluationAttributesObject() {
    EvaluationAttributes e;
    e = new EvaluationAttributes();

    e.courseId = "valid-course";
    e.name = "valid name";
    e.instructions = new Text("1st line of instructions \n 2nd line of instructions");
    e.startTime = TimeHelper.getDateOffsetToCurrentTime(1);
    e.endTime = TimeHelper.getDateOffsetToCurrentTime(2);
    e.activated = false;
    e.published = false;
    e.timeZone = 0.0;
    e.gracePeriod = 5;
    e.p2pEnabled = true;
    return e;
  }
  @Test
  public void testValidate() {
    EvaluationAttributes e = new EvaluationAttributes();

    e.courseId = "";
    e.name = "";
    e.instructions = new Text("Instruction to students.");
    e.startTime = TimeHelper.getDateOffsetToCurrentTime(1);
    e.endTime = TimeHelper.getDateOffsetToCurrentTime(2);
    e.activated = false;
    e.published = false;
    e.timeZone = 0.0;
    e.gracePeriod = 5;
    e.p2pEnabled = true;

    assertEquals("invalid values", false, e.isValid());
    String errorMessage =
        String.format(COURSE_ID_ERROR_MESSAGE, e.courseId, REASON_EMPTY)
            + EOL
            + String.format(EVALUATION_NAME_ERROR_MESSAGE, e.name, REASON_EMPTY);
    assertEquals("valid values", errorMessage, StringHelper.toString(e.getInvalidityInfo()));

    e.courseId = "valid-course";
    e.name = "valid name";
    e.instructions = new Text("valid instructions");
    assertTrue("valid, minimal properties", e.isValid());

    assertEquals("valid values", true, e.isValid());

    e.startTime = null;
    try {
      e.getInvalidityInfo();
      signalFailureToDetectException("null start time not detected");
    } catch (AssertionError e1) {
      ignoreExpectedException();
    }

    e.startTime = TimeHelper.getDateOffsetToCurrentTime(1);
    e.endTime = null;
    try {
      e.getInvalidityInfo();
      signalFailureToDetectException("null end time not detected");
    } catch (AssertionError e1) {
      ignoreExpectedException();
    }

    // SUCCESS : end == start
    e.endTime = TimeHelper.getDateOffsetToCurrentTime(1);
    e.startTime = e.endTime;
    assertTrue(e.isValid());

    // FAIL : end before start
    e.endTime = TimeHelper.getDateOffsetToCurrentTime(1);
    e.startTime = TimeHelper.getDateOffsetToCurrentTime(2);
    assertFalse(e.isValid());
    errorMessage =
        String.format(
            TIME_FRAME_ERROR_MESSAGE, END_TIME_FIELD_NAME, EVALUATION_NAME, START_TIME_FIELD_NAME);
    assertEquals(errorMessage, StringHelper.toString(e.getInvalidityInfo()));

    // FAIL : published before endtime: invalid
    e.published = true;
    e.startTime = TimeHelper.getDateOffsetToCurrentTime(0);
    e.endTime = TimeHelper.getMsOffsetToCurrentTime(5);
    assertFalse(e.isValid());
    assertEquals(
        FieldValidator.EVALUATION_END_TIME_ERROR_MESSAGE,
        StringHelper.toString(e.getInvalidityInfo()));

    // SUCCESS : just after endtime and published: valid
    e.startTime = TimeHelper.getDateOffsetToCurrentTime(-1);
    e.endTime = TimeHelper.getMsOffsetToCurrentTime(-5);
    e.published = true;
    assertTrue(e.isValid());

    // FAIL : activated before start time: invalid
    e.startTime = TimeHelper.getDateOffsetToCurrentTime(1);
    e.endTime = TimeHelper.getDateOffsetToCurrentTime(2);
    e.published = false;
    e.activated = true;
    assertFalse(e.isValid());
    assertEquals(
        FieldValidator.EVALUATION_START_TIME_ERROR_MESSAGE,
        StringHelper.toString(e.getInvalidityInfo()));
  }