HorseDaoTestBase.java 1.44 KB
Newer Older
1 2 3 4 5
package at.ac.tuwien.sepm.assignment.individual.unit.persistence;

import static org.junit.jupiter.api.Assertions.*;

import at.ac.tuwien.sepm.assignment.individual.entity.Horse;
6
import at.ac.tuwien.sepm.assignment.individual.enums.ERace;
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
import at.ac.tuwien.sepm.assignment.individual.persistence.HorseDao;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;

import java.sql.Date;

public abstract class HorseDaoTestBase {

    @Autowired
    HorseDao horseDao;

    @Test
    @DisplayName("Adding a new horse with the correct parameters should return the horse")
    public void addingNewHorse_correctParameters_shouldReturnHorse() {
        String birthday = "2020-01-01";
24
        Horse newHorse = new Horse("Zephyr", "Nice horse", (short) 4, Date.valueOf(birthday), ERace.APPALOOSA, null);
25 26 27 28 29 30 31 32
        Horse savedHorse = horseDao.addHorse(newHorse);
        assertEquals(newHorse, savedHorse);
    }

    @Test
    @DisplayName("Adding a new horse with the incorrect parameters should throw DataAccessException")
    public void addingNewHorse_incorrectParameters_shouldThrowDataAccess() {
        String birthday = "2020-01-01";
33
        Horse newHorse = new Horse("Zephyr", "Nice horse", (short) 80, Date.valueOf(birthday), null, null);
34 35 36 37
        assertThrows(DataAccessException.class, () -> horseDao.addHorse(newHorse));
    }

}