package at.ac.tuwien.sepm.assignment.groupphase; import static junit.framework.TestCase.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDBDAO; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleAdd; import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.VehicleService; import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; import org.junit.Test; public class CarAddTestService { private final VehicleDAO vehicleP = mock(VehicleDBDAO.class); private final VehicleService vehicleService = new VehicleAdd(vehicleP); public CarAddTestService() throws PersistenceException { when(vehicleP.add(any())).thenReturn(1L); } @Test public void testValidVehicleH() { Vehicle vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.HOCHDACH) .type(Vehicle.VehicleType.RTW) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (InvalidVehicleException | ServiceException e) { fail(); } vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.HOCHDACH) .type(Vehicle.VehicleType.KTW) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (InvalidVehicleException | ServiceException e) { fail(); } vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.HOCHDACH) .type(Vehicle.VehicleType.KTW_B) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (InvalidVehicleException | ServiceException e) { fail(); } vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.HOCHDACH) .type(Vehicle.VehicleType.BKTW) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (InvalidVehicleException | ServiceException e) { fail(); } } @Test public void testValidVehicleM() { Vehicle vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) .type(Vehicle.VehicleType.KTW) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (InvalidVehicleException | ServiceException e) { fail(); } vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) .type(Vehicle.VehicleType.KTW_B) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (InvalidVehicleException | ServiceException e) { fail(); } vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) .type(Vehicle.VehicleType.BKTW) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (InvalidVehicleException | ServiceException e) { fail(); } } @Test public void testValidVehicleN() { Vehicle vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.NORMAL) .type(Vehicle.VehicleType.BKTW) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (InvalidVehicleException | ServiceException e) { fail(); } vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.NORMAL) .type(Vehicle.VehicleType.NEF) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (InvalidVehicleException | ServiceException e) { fail(); } vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.NORMAL) .type(Vehicle.VehicleType.NAH) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (InvalidVehicleException | ServiceException e) { fail(); } } @Test(expected = InvalidVehicleException.class) public void testInvalidVehicleH() throws InvalidVehicleException { Vehicle vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.HOCHDACH) .type(Vehicle.VehicleType.NEF) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (ServiceException e) { fail(); } vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.HOCHDACH) .type(Vehicle.VehicleType.NAH) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (ServiceException e) { fail(); } } @Test(expected = InvalidVehicleException.class) public void testInvalidVehicleM() throws InvalidVehicleException { Vehicle vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) .type(Vehicle.VehicleType.NEF) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (ServiceException e) { fail(); } vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) .type(Vehicle.VehicleType.NAH) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (ServiceException e) { fail(); } vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) .type(Vehicle.VehicleType.RTW) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (ServiceException e) { fail(); } } @Test(expected = InvalidVehicleException.class) public void testInvalidVehicleN() throws InvalidVehicleException { Vehicle vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.NORMAL) .type(Vehicle.VehicleType.RTW) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (ServiceException e) { fail(); } vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.NORMAL) .type(Vehicle.VehicleType.KTW_B) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (ServiceException e) { fail(); } vehicle = Vehicle.builder() .constructionType(Vehicle.ConstructionType.NORMAL) .type(Vehicle.VehicleType.KTW) .hasNef(true) .status(Vehicle.Status.ABGEMELDET) .name("") .build(); try { vehicleService.add(vehicle); } catch (ServiceException e) { fail(); } } }