Skip to content
Snippets Groups Projects
CarTest.java 1.29 KiB
Newer Older
MarvinKlemp's avatar
MarvinKlemp committed
package car;

import car.exception.CarIsUnavailableException;
MarvinKlemp's avatar
MarvinKlemp committed
import car.exception.NoNeedToRepairCarException;
MarvinKlemp's avatar
MarvinKlemp committed
import car.exception.UnableToRentCarException;
MarvinKlemp's avatar
MarvinKlemp committed

MarvinKlemp's avatar
MarvinKlemp committed
import org.junit.Assert;
MarvinKlemp's avatar
MarvinKlemp committed
import org.junit.Test;
MarvinKlemp's avatar
MarvinKlemp committed

MarvinKlemp's avatar
MarvinKlemp committed
public class CarTest {
    @Test(expected = CarIsUnavailableException.class)
    public void sellThrowsCarIsUnavailableExceptionIfCarIsUnavailable() throws CarIsUnavailableException {
        Car car = new Car(1, 1000, 100, 100);
MarvinKlemp's avatar
MarvinKlemp committed

MarvinKlemp's avatar
MarvinKlemp committed
        car.sell();
        car.sell();
MarvinKlemp's avatar
MarvinKlemp committed
    }
MarvinKlemp's avatar
MarvinKlemp committed

    @Test(expected = NoNeedToRepairCarException.class)
    public void repairThrowsNoNeedToRepairCarExceptionIfCarIsNowDamaged() throws NoNeedToRepairCarException {
        Car car = new Car(1, 1000, 100, 100);
MarvinKlemp's avatar
MarvinKlemp committed

        car.repair();
    }
MarvinKlemp's avatar
MarvinKlemp committed
    @Test(expected = IllegalArgumentException.class)
    public void rentThrowsIllegalArgumentExceptionWithNegativeMonthsArgument() throws UnableToRentCarException {
        Car car = new Car(1, 1000, 100, 100);
MarvinKlemp's avatar
MarvinKlemp committed

        car.rent(-10);
    }

    @Test(expected = UnableToRentCarException.class)
    public void rentThrowsUnableToRentCarExceptionIfAlreadyRented() throws UnableToRentCarException {
        Car car = new Car(1, 1000, 100, 100);
MarvinKlemp's avatar
MarvinKlemp committed

        try {
            car.rent(10);
        } catch (UnableToRentCarException e) {
            Assert.fail();
        }

        car.rent(10);
    }
MarvinKlemp's avatar
MarvinKlemp committed
}