OwnerDaoTestBase.java 1.48 KB
Newer Older
1 2 3 4
package at.ac.tuwien.sepm.assignment.individual.unit.persistence;

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

5
import at.ac.tuwien.sepm.assignment.individual.entity.Owner;
6 7 8 9 10
import at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException;
import at.ac.tuwien.sepm.assignment.individual.persistence.OwnerDao;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.dao.DataAccessException;
12 13 14 15 16 17 18 19 20 21

public abstract class OwnerDaoTestBase {

    @Autowired
    OwnerDao ownerDao;

    @Test
    @DisplayName("Finding owner by non-existing ID should throw NotFoundException")
    public void findingOwnerById_nonExisting_shouldThrowNotFoundException() {
        assertThrows(NotFoundException.class,
22
            () -> ownerDao.findOneById(0L));
23 24
    }

25 26 27 28 29 30 31 32 33 34 35 36 37 38
    @Test
    @DisplayName("Adding a new owner with the correct parameters should return the owner")
    public void addingNewOwner_correctParameters_shouldReturnOwner() {
        Owner newOwner = new Owner("Chad");
        Owner savedOwner = ownerDao.addOwner(newOwner);
        assertEquals(newOwner, savedOwner);
    }

    @Test
    @DisplayName("Adding a new horse with the incorrect parameters should throw DataAccessException")
    public void addingNewOwner_incorrectParameters_shouldThrowDataAccess() {
        Owner newOwner = new Owner("");
        assertThrows(DataAccessException.class, () -> ownerDao.addOwner(newOwner));
    }
39
}