From 3dfdd195b1f47203ae8bdfcf604dc2a201d38ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luc=C3=A0s?= Date: Thu, 28 Mar 2024 00:44:38 +0100 Subject: [PATCH] test(DevWeb): Add tests in Game_JPA_DAO_FactoryTest --- .../dao/jpa/Game_JPA_DAO_FactoryTest.java | 71 +++++++++++++++---- 1 file changed, 58 insertions(+), 13 deletions(-) diff --git a/S2/DevWeb/Projet/src/test/java/uppa/project/dao/jpa/Game_JPA_DAO_FactoryTest.java b/S2/DevWeb/Projet/src/test/java/uppa/project/dao/jpa/Game_JPA_DAO_FactoryTest.java index c9713a2..5cbf529 100644 --- a/S2/DevWeb/Projet/src/test/java/uppa/project/dao/jpa/Game_JPA_DAO_FactoryTest.java +++ b/S2/DevWeb/Projet/src/test/java/uppa/project/dao/jpa/Game_JPA_DAO_FactoryTest.java @@ -1,32 +1,77 @@ package uppa.project.dao.jpa; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import uppa.project.dao.DAO; +import uppa.project.dao.DAOException; +import uppa.project.pojo.User; +import uppa.project.provider.EntityManagerProvider; import static org.junit.jupiter.api.Assertions.*; class Game_JPA_DAO_FactoryTest { - @Test - void getDAOUser() { - // TODO Implement this method - fail(); + static Game_JPA_DAO_Factory factory; + + @BeforeAll + static void setUp() { + EntityManagerProvider.setPersitenceUnitName("test"); + factory = new Game_JPA_DAO_Factory(); } @Test - void getDAOGame() { - // TODO Implement this method - fail(); + void test_getDAOUser() throws DAOException { + // If the method throws an exception, make sure the database is running + assertDoesNotThrow(() -> factory.getDAOUser()); + + // Check if the returned object is a DAO + assertNotNull(factory.getDAOUser()); + + // Check if the object is unique + DAO dao1 = factory.getDAOUser(); + DAO dao2 = factory.getDAOUser(); + assertEquals(dao1, dao2); } @Test - void getDAOPlayer() { - // TODO Implement this method - fail(); + void test_getDAOGame() throws DAOException { + // If the method throws an exception, make sure the database is running + assertDoesNotThrow(() -> factory.getDAOGame()); + + // Check if the returned object is a DAO + assertNotNull(factory.getDAOGame()); + + // Check if the object is unique + DAO dao1 = factory.getDAOUser(); + DAO dao2 = factory.getDAOUser(); + assertEquals(dao1, dao2); } @Test - void getDAORecoveryPasswordToken() { - // TODO Implement this method - fail(); + void test_getDAOPlayer() throws DAOException { + // If the method throws an exception, make sure the database is running + assertDoesNotThrow(() -> factory.getDAOPlayer()); + + // Check if the returned object is a DAO + assertNotNull(factory.getDAOPlayer()); + + // Check if the object is unique + DAO dao1 = factory.getDAOUser(); + DAO dao2 = factory.getDAOUser(); + assertEquals(dao1, dao2); + } + + @Test + void test_getDAORecoveryPasswordToken() throws DAOException { + // If the method throws an exception, make sure the database is running + assertDoesNotThrow(() -> factory.getDAORecoveryPasswordToken()); + + // Check if the returned object is a DAO + assertNotNull(factory.getDAORecoveryPasswordToken()); + + // Check if the object is unique + DAO dao1 = factory.getDAOUser(); + DAO dao2 = factory.getDAOUser(); + assertEquals(dao1, dao2); } }