GradeServiceImpl implements GradeService { @Override public void addGrade(Grade g) { entityManager.persist(g); }  @Override void addGrade(Grade g); @Override void deleteGrade(Long gradeId); @Override List<Grade> getAllGradesForStudent(String studentId); @Override Map<Discipline, Double> getAvgGradesForStudent(String studentId); @Override Double getTotalAvgForStudent(String studentId); @Override Double getAvgForStudents(List<String> studentsId); @Override Long getNbGradesForStudents(List<String> studentsIds); @Override Long getNbGradesForStudents(List<String> studentsIds, Discipline discipline); @Override Long getNbGradesForStudent(String studentId, Discipline discipline); @Override Long getNbGradesForStudent(String studentId); @Override Double getAvgForStudentsAndDiscipline(List<String> studentsId, Discipline discipline);  }
@Test public void shouldAddAGrade() { TypedQuery<Grade> query = em.createQuery("SELECT g FROM Grade g", Grade.class); List<Grade> results = query.getResultList(); int numberOfGrades = results.size(); query = em.createQuery("SELECT g FROM Grade g where g.studentId = :studentId", Grade.class); query.setParameter("studentId", "001"); int numberOf001Grades = query.getResultList().size(); Grade g = new Grade("001", new Date(), Discipline.BIOLOGY, 40); service.addGrade(g); g = new Grade("001", new Date(), Discipline.MATHEMATICS, 10); service.addGrade(g); g = new Grade("001", new Date(), Discipline.ENGLISH, 20); service.addGrade(g); g = new Grade("002", new Date(), Discipline.ENGLISH, 40); service.addGrade(g); query = em.createQuery("SELECT g FROM Grade g", Grade.class); results = query.getResultList(); Assert.assertEquals(numberOfGrades + 4, results.size()); query = em.createQuery("SELECT g FROM Grade g where g.studentId = :studentId", Grade.class); query.setParameter("studentId", "001"); results = query.getResultList(); Assert.assertEquals(numberOf001Grades + 3, results.size()); }