From 4f59d1c70102ea9b96d4bba8760737133e1fd4c3 Mon Sep 17 00:00:00 2001 From: Dominika Zemanovicova <xzemanov@fi.muni.cz> Date: Sun, 16 Apr 2023 21:39:54 +0200 Subject: [PATCH] ExerciseRepositoryTest add flush --- .../exercise/ExerciseRepositoryTest.java | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/application/module-exercise/src/test/java/org/fuseri/moduleexercise/exercise/ExerciseRepositoryTest.java b/application/module-exercise/src/test/java/org/fuseri/moduleexercise/exercise/ExerciseRepositoryTest.java index 8eb27c57..1d8eec54 100644 --- a/application/module-exercise/src/test/java/org/fuseri/moduleexercise/exercise/ExerciseRepositoryTest.java +++ b/application/module-exercise/src/test/java/org/fuseri/moduleexercise/exercise/ExerciseRepositoryTest.java @@ -1,6 +1,5 @@ package org.fuseri.moduleexercise.exercise; -import org.fuseri.moduleexercise.question.Question; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -11,8 +10,6 @@ import org.springframework.data.domain.PageRequest; import java.util.Arrays; import java.util.HashSet; -import java.util.Set; - @DataJpaTest class ExerciseRepositoryTest { @@ -25,8 +22,6 @@ class ExerciseRepositoryTest { Exercise exercise = new Exercise("name", "desc", 2, 1L, new HashSet<>()); - Question question = new Question("text", new HashSet<>(), exercise); - @Test void saveExercise() { Exercise saved = exerciseRepository.save(exercise); @@ -64,6 +59,7 @@ class ExerciseRepositoryTest { entityManager.persist(exercise); entityManager.persist(exercise1); + entityManager.flush(); Page<Exercise> coursePage = exerciseRepository.findAll(PageRequest.of(0, 42)); @@ -71,26 +67,6 @@ class ExerciseRepositoryTest { Assertions.assertEquals(coursePage.getContent(), Arrays.asList(exercise, exercise1)); } - @Test - void getQuestionsEmptyQuestions() { - entityManager.persist(exercise); - - var result = exerciseRepository.getQuestions(PageRequest.of(0, 10), 1L); - - Assertions.assertEquals(0, result.getTotalElements()); - } - - @Test - void getQuestions() { - exercise.setQuestions(Set.of(question)); - entityManager.persist(exercise); - - var result = exerciseRepository.getQuestions(PageRequest.of(0, 10), 1L); - - Assertions.assertEquals(1, result.getTotalElements()); - Assertions.assertEquals(result.getContent().get(0), question); - } - @Test void testDeleteExercise() { Long id = entityManager.persist(exercise).getId(); @@ -101,5 +77,4 @@ class ExerciseRepositoryTest { Assertions.assertTrue(exerciseRepository.findById(id).isEmpty()); } - } -- GitLab