@Test
 public void canAddQuestion() {
   questionManager.addQuestion(question);
   questionDatabase.switchMode(QuestionMode.CUSTOM_ONLY);
   int number = questionDatabase.getNumberOfQuestions(question.getLevel());
   Question loadedQuestion =
       questionDatabase.getQuestion(question.getLevel(), question.getCategory(), number - 1);
   assertEquals(oldNumberOfQuestions + 1, number);
   assertEquals("Questions do not match", question, loadedQuestion);
 }
 @After
 public void cleanup() {
   questionDatabase = QuestionDatabaseFactory.aQuestionDatabaseWithOnlyCustomQuestions();
   int numberToDelete =
       questionDatabase.getNumberOfQuestions(question.getLevel()) - oldNumberOfQuestions;
   for (int ii = 0; ii < numberToDelete; ii++) {
     Question questionToDelete =
         questionDatabase.getQuestion(
             question.getLevel(), question.getCategory(), oldNumberOfQuestions + ii);
     questionManager.deleteQuestion(questionToDelete);
   }
 }
  /*
      @Test
      public void canDeleteQuestion() {
          canAddQuestion();
          questionManager.deleteQuestion(question);
          questionDatabase = QuestionDatabaseFactory.aQuestionDatabaseWithOnlyCustomQuestions();
          int number = questionDatabase.getNumberOfQuestions(question.getLevel());
          assertEquals(oldNumberOfQuestions, number);
      }
  */
  @Test
  public void canEditQuestion() {
    final String newQuestionString = "HELLO THIS IS ME";

    questionManager.addQuestion(question);
    questionDatabase = QuestionDatabaseFactory.aQuestionDatabaseWithOnlyCustomQuestions();
    Question newQuestion = QuestionBuilder.aQuestion().copiedFrom(question).build();
    newQuestion.setQuestion(newQuestionString);
    questionManager.editQuestion(question, newQuestion);
    questionDatabase = QuestionDatabaseFactory.aQuestionDatabaseWithOnlyCustomQuestions();

    int number = questionDatabase.getNumberOfQuestions(question.getLevel()) - 1;
    Question loadedQuestion =
        questionDatabase.getQuestion(question.getLevel(), question.getCategory(), number);

    assertEquals("Question not edited", newQuestion, loadedQuestion);
  }
Esempio n. 4
0
  /** Create a user, create a state and make him answer a few questions. */
  @Before
  public void setup() {

    // setup user
    expectedUser = new User("xuser");
    expectedUser.setId(1234);

    // setup level
    expectedLevel = QuestionLevel.LEVEL_1;

    // setup question
    expectedQuestion = new Question();
    expectedQuestion.setAnswer("xanswer");
    expectedQuestion.setType(QuestionType.TEXT);
    expectedQuestion.setCategory(QuestionCategory.SHAPES);
    List<String> choices = new ArrayList();
    choices.add("apple");
    choices.add("orange");
    choices.add("banana");
    choices.add("cherry");
    expectedQuestion.setChoices(choices);
    expectedQuestion.setLevel(expectedLevel);
    expectedQuestion.setQuestion("xquestion");
    expectedQuestion.setExplaination("xplanation");

    // set current question and level for user
    expectedUser.setCurrentQuestion(expectedQuestion);
    expectedUser.endState();
    fileUserManager.addUser(expectedUser);
  }
 @Before
 public void setup() {
   questionDatabase = QuestionDatabaseFactory.aQuestionDatabaseWithOnlyCustomQuestions();
   questionManager = QuestionDatabaseFactory.aQuestionManager();
   question =
       QuestionBuilder.aQuestion()
           .asking("What has four sides?")
           .ofType(QuestionType.TEXT)
           .withChoices("Square", "Circle", "Triangle", "Oval")
           .withAnswer("Square")
           .withExplaination("A square has four equal sides")
           .ofLevel(QuestionLevel.LEVEL_1)
           .inCategory(QuestionCategory.SHAPES)
           .build();
   oldNumberOfQuestions = questionDatabase.getNumberOfQuestions(question.getLevel());
 }