Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package carTrip;
- import org.junit.Assert;
- import org.junit.Before;
- import org.junit.Test;
- public class CarTest {
- private static final String MODEL = "Audi";
- private static final String EMPTY_STRING = "";
- private static final int INIT_FUEL_AMOUNT = 15;
- private static final int INIT_FUEL_CONSUMPTION_PER_KM = 10;
- private static final int INIT_TANK_CAPACITY = 20;
- private Car car;
- @Before
- public void createCar() {
- car = new Car(MODEL, INIT_TANK_CAPACITY, INIT_FUEL_AMOUNT, INIT_FUEL_CONSUMPTION_PER_KM);
- }
- @Test
- public void testGetModelFunctionality() {
- Assert.assertTrue("Car doesn't return the right model!", car.getModel().equals(MODEL));
- }
- @Test
- public void testSetTankCapacityFunctionality() {
- Assert.assertTrue("Car doesn't return the right model!", car.getTankCapacity() == INIT_TANK_CAPACITY);
- }
- @Test
- public void testGetTankCapacityFunctionality() {
- Assert.assertTrue("Car doesn't return the right tankCapacity!", car.getTankCapacity() == INIT_TANK_CAPACITY);
- }
- @Test
- public void testGetFuelAmountFunctionality() {
- Assert.assertTrue("Car doesn't return the right fuelAmount!", car.getFuelAmount() == INIT_FUEL_AMOUNT);
- }
- @Test
- public void testGetFuelConsumptionPerKmFunctionality() {
- Assert.assertTrue("Car doesn't return the right fuelConsumption!", car.getFuelConsumptionPerKm() == INIT_FUEL_CONSUMPTION_PER_KM);
- }
- @Test(expected = IllegalArgumentException.class)
- public void testSetModelWithNull() {
- new Car(null, 2, 2, 2);
- }
- @Test(expected = IllegalArgumentException.class)
- public void testSetModelWitEmptyInput() {
- new Car(EMPTY_STRING, 2, 2, 2);
- }
- @Test(expected = IllegalArgumentException.class)
- public void testSetFuelAmountWitHigherFuelAmount() {
- new Car(MODEL, 3, 4, 2);
- }
- @Test(expected = IllegalArgumentException.class)
- public void testSetFuelConsumptionPerKmWitZero() {
- new Car(MODEL, 2, 1, 0);
- }
- @Test(expected = IllegalArgumentException.class)
- public void testSetFuelConsumptionPerKmWitNegativeNumber() {
- new Car(MODEL, 2, 1, -10);
- }
- @Test(expected = IllegalStateException.class)
- public void testDrive() {
- car.drive(2);
- }
- @Test
- public void testDriveWithCorrectParameters() {
- String drive = car.drive(1);
- Assert.assertTrue("Cannot drive that amount of kilometers", drive.equals("Have a nice trip"));
- }
- @Test(expected = IllegalStateException.class)
- public void testRefuel() {
- car.refuel(10);
- }
- @Test
- public void testRefuelWithCorrectParameters() {
- car.refuel(3);
- Assert.assertTrue("Cannot refuel that amount of liters", car.getFuelAmount() == 3 + INIT_FUEL_AMOUNT);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement