OwnerServiceTest.java 1.53 KB
Newer Older
1 2 3 4 5 6 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 32 33 34 35 36 37 38 39
package at.ac.tuwien.sepm.assignment.individual.unit.service;

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

import at.ac.tuwien.sepm.assignment.individual.entity.Owner;
import at.ac.tuwien.sepm.assignment.individual.service.OwnerService;
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 static org.junit.jupiter.api.Assertions.assertEquals;

@ExtendWith(SpringExtension.class)
@SpringBootTest
@ActiveProfiles("test")
public class OwnerServiceTest {
    @Autowired
    OwnerService ownerService;

    @Test
    @DisplayName("Adding a new owner with the correct parameters will return the new owner")
    public void addingNewOwner_correctParameters_shouldReturnOwner() {
        Owner newOwner = new Owner("Chad");
        Owner savedOwner = ownerService.addOwner(newOwner);
        assertEquals(newOwner, savedOwner);
    }

    @Test
    @DisplayName("Adding a new owner with the incorrect parameters will throw a ValidationException")
    public void addingNewOwner_incorrectParameters_shouldThrowValidation() {
        Owner newOwner = new Owner("");
        assertThrows(ValidationException.class, () -> ownerService.addOwner(newOwner));
    }
}