HorseServiceTest.java 1.83 KB
Newer Older
1 2 3 4 5
package at.ac.tuwien.sepm.assignment.individual.unit.service;

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 24 25 26 27 28 29 30 31
import at.ac.tuwien.sepm.assignment.individual.service.HorseService;
import at.ac.tuwien.sepm.assignment.individual.util.ValidationException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.sql.Date;

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

@ExtendWith(SpringExtension.class)
@SpringBootTest
@ActiveProfiles("test")
public class HorseServiceTest {
    @Autowired
    HorseService horseService;

    @Test
    @DisplayName("Adding a new horse with the correct parameters will return the new horse")
    public void addingNewHorse_correctParameters_shouldReturnHorse() {
        String birthday = "2020-01-01";
32
        Horse newHorse = new Horse("Zephyr", "Nice horse", (short) 4, Date.valueOf(birthday), ERace.APPALOOSA, null);
33 34 35 36 37 38 39 40
        Horse savedHorse = horseService.addHorse(newHorse);
        assertEquals(newHorse, savedHorse);
    }

    @Test
    @DisplayName("Adding a new horse with the incorrect parameters will throw a ValidationException")
    public void addingNewHorse_incorrectParameters_shouldThrowValidation() {
        String birthday = "2020-01-01";
41
        Horse newHorse = new Horse("Zephyr", "Nice horse", (short) 80, Date.valueOf(birthday), null, null);
42 43 44
        assertThrows(ValidationException.class, () -> horseService.addHorse(newHorse));
    }
}