Maven Classifier (#11833)
* maven classifier * static imports * bumped up plugin versions Co-authored-by: s9m33r <no-reply>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.maven.dependency.classifier.provider.factory;
|
||||
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car;
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car.Type;
|
||||
|
||||
public class CarFactory {
|
||||
|
||||
public static Car manufacture(Type carType) {
|
||||
Car car = new Car();
|
||||
car.setType(carType);
|
||||
|
||||
return car;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.maven.dependency.classifier.provider.model;
|
||||
|
||||
public class Car {
|
||||
private Type type;
|
||||
private PowerSource fuelType;
|
||||
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(Type carType) {
|
||||
this.type = carType;
|
||||
}
|
||||
|
||||
public PowerSource getPowerSource() {
|
||||
return this.fuelType;
|
||||
}
|
||||
|
||||
public void setFuelType(PowerSource fuelType) {
|
||||
this.fuelType = fuelType;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
ELECTRIC
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.baeldung.maven.dependency.classifier.provider.model;
|
||||
|
||||
public enum PowerSource {
|
||||
BATTERY
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
package com.baeldung.maven.dependency.classifier.provider.factory;
|
||||
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car;
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car.Type;
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.PowerSource;
|
||||
import com.baeldung.maven.dependency.classifier.provider.stub.CarStub;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
class CarFactoryUnitTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Given Car type When CarFactory manufacture is called Then create a Car of the given type")
|
||||
public void givenCarType_whenCarFactoryManufactureCalled_thenCreateCarOfGivenType() {
|
||||
Car car = CarFactory.manufacture(Type.ELECTRIC);
|
||||
|
||||
assertNotNull(car, "CarFactory didn't manufacture a car. Car is null");
|
||||
assertEquals(Type.ELECTRIC, car.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Given an electric car When asked for fuel type Then return Battery")
|
||||
public void givenElectricCar_whenAskedForFuelType_thenReturnBattery() {
|
||||
Car car = CarStub.ELECTRIC_CAR;
|
||||
|
||||
assertEquals(PowerSource.BATTERY, car.getPowerSource());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.maven.dependency.classifier.provider.stub;
|
||||
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car;
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.PowerSource;
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car.Type;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class CarStub {
|
||||
public static Car ELECTRIC_CAR = Mockito.mock(Car.class);
|
||||
|
||||
static {
|
||||
when(ELECTRIC_CAR.getType()).thenReturn(Type.ELECTRIC);
|
||||
when(ELECTRIC_CAR.getPowerSource()).thenReturn(PowerSource.BATTERY);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user