Advertisement
bobo_bobkata

Untitled

Jul 31st, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.88 KB | None | 0 0
  1. package carTrip;
  2.  
  3. import org.junit.Assert;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6.  
  7. public class CarTest {
  8.  
  9.     private static final String MODEL = "Audi";
  10.     private static final String EMPTY_STRING = "";
  11.     private static final int INIT_FUEL_AMOUNT = 15;
  12.     private static final int INIT_FUEL_CONSUMPTION_PER_KM = 10;
  13.     private static final int INIT_TANK_CAPACITY = 20;
  14.  
  15.     private Car car;
  16.  
  17.  
  18.     @Before
  19.     public void createCar() {
  20.         car = new Car(MODEL, INIT_TANK_CAPACITY, INIT_FUEL_AMOUNT, INIT_FUEL_CONSUMPTION_PER_KM);
  21.     }
  22.  
  23.     @Test
  24.     public void testGetModelFunctionality() {
  25.         Assert.assertTrue("Car doesn't return the right model!", car.getModel().equals(MODEL));
  26.     }
  27.  
  28.     @Test
  29.     public void testSetTankCapacityFunctionality() {
  30.         Assert.assertTrue("Car doesn't return the right model!", car.getTankCapacity() == INIT_TANK_CAPACITY);
  31.     }
  32.  
  33.     @Test
  34.     public void testGetTankCapacityFunctionality() {
  35.         Assert.assertTrue("Car doesn't return the right tankCapacity!", car.getTankCapacity() == INIT_TANK_CAPACITY);
  36.     }
  37.  
  38.     @Test
  39.     public void testGetFuelAmountFunctionality() {
  40.         Assert.assertTrue("Car doesn't return the right fuelAmount!", car.getFuelAmount() == INIT_FUEL_AMOUNT);
  41.     }
  42.  
  43.     @Test
  44.     public void testGetFuelConsumptionPerKmFunctionality() {
  45.         Assert.assertTrue("Car doesn't return the right fuelConsumption!", car.getFuelConsumptionPerKm() == INIT_FUEL_CONSUMPTION_PER_KM);
  46.     }
  47.  
  48.     @Test(expected = IllegalArgumentException.class)
  49.     public void testSetModelWithNull() {
  50.         new Car(null, 2, 2, 2);
  51.     }
  52.  
  53.     @Test(expected = IllegalArgumentException.class)
  54.     public void testSetModelWitEmptyInput() {
  55.         new Car(EMPTY_STRING, 2, 2, 2);
  56.     }
  57.  
  58.     @Test(expected = IllegalArgumentException.class)
  59.     public void testSetFuelAmountWitHigherFuelAmount() {
  60.         new Car(MODEL, 3, 4, 2);
  61.     }
  62.  
  63.     @Test(expected = IllegalArgumentException.class)
  64.     public void testSetFuelConsumptionPerKmWitZero() {
  65.         new Car(MODEL, 2, 1, 0);
  66.     }
  67.  
  68.     @Test(expected = IllegalArgumentException.class)
  69.     public void testSetFuelConsumptionPerKmWitNegativeNumber() {
  70.         new Car(MODEL, 2, 1, -10);
  71.     }
  72.  
  73.     @Test(expected = IllegalStateException.class)
  74.     public void testDrive() {
  75.         car.drive(2);
  76.     }
  77.  
  78.     @Test
  79.     public void testDriveWithCorrectParameters() {
  80.         String drive = car.drive(1);
  81.         Assert.assertTrue("Cannot drive that amount of kilometers", drive.equals("Have a nice trip"));
  82.     }
  83.  
  84.     @Test(expected = IllegalStateException.class)
  85.     public void testRefuel() {
  86.         car.refuel(10);
  87.     }
  88.  
  89.     @Test
  90.     public void testRefuelWithCorrectParameters() {
  91.         car.refuel(3);
  92.         Assert.assertTrue("Cannot refuel that amount of liters", car.getFuelAmount() == 3 + INIT_FUEL_AMOUNT);
  93.     }
  94.  
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement