@Test public void testCreateQuiz(){ long subId = createCtgAndSub("foo","bar"); String question = "Will this test work?"; long quizId = quizService.createQuiz(subId, question, "yes", "no", "may", "no idea", 0); assertEquals(1, quizService.getQuizzes().size()); assertEquals(question, quizService.getQuiz(quizId).getQuestion()); }
public long createQuiz( long subCategoryId, String question, String firstAnswer, String secondAnswer, String thirdAnswer, String fourthAnswer, int indexOfCorrectAnswer ){ SubCategory subCategory = em.find(SubCategory.class, subCategoryId); if(subCategory == null){ throw new IllegalArgumentException("SubCategory "+subCategoryId+" does not exist"); } Quiz quiz = new Quiz(); quiz.setSubCategory(subCategory); quiz.setQuestion(question); quiz.setFirstAnswer(firstAnswer); quiz.setSecondAnswer(secondAnswer); quiz.setThirdAnswer(thirdAnswer); quiz.setFourthAnswer(fourthAnswer); quiz.setIndexOfCorrectAnswer(indexOfCorrectAnswer); em.persist(quiz); return quiz.getId(); }
QuizService { public long createQuiz( long subCategoryId, String question, String firstAnswer, String secondAnswer, String thirdAnswer, String fourthAnswer, int indexOfCorrectAnswer ){ SubCategory subCategory = em.find(SubCategory.class, subCategoryId); if(subCategory == null){ throw new IllegalArgumentException("SubCategory "+subCategoryId+" does not exist"); } Quiz quiz = new Quiz(); quiz.setSubCategory(subCategory); quiz.setQuestion(question); quiz.setFirstAnswer(firstAnswer); quiz.setSecondAnswer(secondAnswer); quiz.setThirdAnswer(thirdAnswer); quiz.setFourthAnswer(fourthAnswer); quiz.setIndexOfCorrectAnswer(indexOfCorrectAnswer); em.persist(quiz); return quiz.getId(); } }
QuizService { public long createQuiz( long subCategoryId, String question, String firstAnswer, String secondAnswer, String thirdAnswer, String fourthAnswer, int indexOfCorrectAnswer ){ SubCategory subCategory = em.find(SubCategory.class, subCategoryId); if(subCategory == null){ throw new IllegalArgumentException("SubCategory "+subCategoryId+" does not exist"); } Quiz quiz = new Quiz(); quiz.setSubCategory(subCategory); quiz.setQuestion(question); quiz.setFirstAnswer(firstAnswer); quiz.setSecondAnswer(secondAnswer); quiz.setThirdAnswer(thirdAnswer); quiz.setFourthAnswer(fourthAnswer); quiz.setIndexOfCorrectAnswer(indexOfCorrectAnswer); em.persist(quiz); return quiz.getId(); }  }
QuizService { public long createQuiz( long subCategoryId, String question, String firstAnswer, String secondAnswer, String thirdAnswer, String fourthAnswer, int indexOfCorrectAnswer ){ SubCategory subCategory = em.find(SubCategory.class, subCategoryId); if(subCategory == null){ throw new IllegalArgumentException("SubCategory "+subCategoryId+" does not exist"); } Quiz quiz = new Quiz(); quiz.setSubCategory(subCategory); quiz.setQuestion(question); quiz.setFirstAnswer(firstAnswer); quiz.setSecondAnswer(secondAnswer); quiz.setThirdAnswer(thirdAnswer); quiz.setFourthAnswer(fourthAnswer); quiz.setIndexOfCorrectAnswer(indexOfCorrectAnswer); em.persist(quiz); return quiz.getId(); }  List<Quiz> getRandomQuizzes(int n, long categoryId); long createQuiz(
            long subCategoryId,
            String question,
            String firstAnswer,
            String secondAnswer,
            String thirdAnswer,
            String fourthAnswer,
            int indexOfCorrectAnswer
    ); List<Quiz> getQuizzes(); Quiz getQuiz(long id); }
QuizService { public long createQuiz( long subCategoryId, String question, String firstAnswer, String secondAnswer, String thirdAnswer, String fourthAnswer, int indexOfCorrectAnswer ){ SubCategory subCategory = em.find(SubCategory.class, subCategoryId); if(subCategory == null){ throw new IllegalArgumentException("SubCategory "+subCategoryId+" does not exist"); } Quiz quiz = new Quiz(); quiz.setSubCategory(subCategory); quiz.setQuestion(question); quiz.setFirstAnswer(firstAnswer); quiz.setSecondAnswer(secondAnswer); quiz.setThirdAnswer(thirdAnswer); quiz.setFourthAnswer(fourthAnswer); quiz.setIndexOfCorrectAnswer(indexOfCorrectAnswer); em.persist(quiz); return quiz.getId(); }  List<Quiz> getRandomQuizzes(int n, long categoryId); long createQuiz(
            long subCategoryId,
            String question,
            String firstAnswer,
            String secondAnswer,
            String thirdAnswer,
            String fourthAnswer,
            int indexOfCorrectAnswer
    ); List<Quiz> getQuizzes(); Quiz getQuiz(long id);  }