package dao; import dao.DataAccessException; import dao.Database; import dao.EventDAO; import model.Event; import model.Person; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.sql.Connection; import static org.junit.jupiter.api.Assertions.*; public class EventDAOTest { private Database db; private Event insertEvent; private Event retrieveEvent; private EventDAO eDao; @BeforeEach public void setUp() throws DataAccessException { db = new Database(); insertEvent = new Event("Biking_123A", "Gale", "Gale123A", 35.9f, 140.1f, "Japan", "Ushiku", "Biking_Around", 2016); retrieveEvent = new Event("2351243", "Dale", "Dale123", 37.2f, 104.4f, "USA", "Provo", "EatingDinner", 2021); Connection conn = db.getConnection(); db.clearTables(); eDao = new EventDAO(conn); } @AfterEach public void tearDown() throws DataAccessException { db.closeConnection(false); } @Test public void insertPass() throws DataAccessException { Event compareTest = eDao.getEventByID(insertEvent.getPersonID()); assertNull(compareTest); eDao.createEvent(insertEvent); compareTest = eDao.getEventByID(insertEvent.getEventID()); assertEquals(insertEvent, compareTest); } @Test public void insertFail() throws DataAccessException { eDao.createEvent(insertEvent); assertThrows(DataAccessException.class, ()-> eDao.createEvent(insertEvent)); } @Test public void retrievalPass() throws DataAccessException { eDao.createEvent(retrieveEvent); Event compareTest = eDao.getEventByID(retrieveEvent.getEventID()); assertNotNull(compareTest); assertEquals(retrieveEvent, compareTest); } @Test public void retrievalFail() throws DataAccessException { Event compareTest = eDao.getEventByID("153467"); assertEquals(compareTest, null); } @Test public void clearPass() throws DataAccessException { eDao.createEvent(insertEvent); assertNotNull(eDao.getEventByID(insertEvent.getEventID())); assertDoesNotThrow(() -> eDao.removeAllEvents()); assertNull(eDao.getEventByID(insertEvent.getEventID())); } }