diff --git a/maven-modules/maven-classifier/maven-classifier-example-consumer/pom.xml b/maven-modules/maven-classifier/maven-classifier-example-consumer/pom.xml new file mode 100644 index 0000000000..cbf046ed5a --- /dev/null +++ b/maven-modules/maven-classifier/maven-classifier-example-consumer/pom.xml @@ -0,0 +1,53 @@ + + + + maven-classifier + com.baeldung + 0.0.1-SNAPSHOT + + + 4.0.0 + + maven-classifier-example-consumer + + + 8 + 8 + + + + + com.baeldung + maven-classifier-example-provider + 0.0.1-SNAPSHOT + + + com.baeldung + maven-classifier-example-provider + 0.0.1-SNAPSHOT + arbitrary + + + + + + + + + + com.baeldung + maven-classifier-example-provider + 0.0.1-SNAPSHOT + sources + + + com.baeldung + maven-classifier-example-provider + 0.0.1-SNAPSHOT + tests + + + + diff --git a/maven-modules/maven-classifier/maven-classifier-example-consumer/src/main/java/com/baeldung/maven/classifier/consumer/FuelStation.java b/maven-modules/maven-classifier/maven-classifier-example-consumer/src/main/java/com/baeldung/maven/classifier/consumer/FuelStation.java new file mode 100644 index 0000000000..cf5dc03457 --- /dev/null +++ b/maven-modules/maven-classifier/maven-classifier-example-consumer/src/main/java/com/baeldung/maven/classifier/consumer/FuelStation.java @@ -0,0 +1,17 @@ + +package com.baeldung.maven.classifier.consumer; + +import com.baeldung.maven.dependency.classifier.provider.model.Car; +import com.baeldung.maven.dependency.classifier.provider.model.PowerSource; + +public class FuelStation { + + public FuelStation.Zone refill(Car car) { + return PowerSource.BATTERY.equals(car.getPowerSource()) ? FuelStation.Zone.BATTERY : FuelStation.Zone.UNKNOWN; + } + + public enum Zone { + BATTERY, + UNKNOWN + } +} diff --git a/maven-modules/maven-classifier/maven-classifier-example-consumer/src/test/java/com/baeldung/maven/classifier/consumer/FuelStationUnitTest.java b/maven-modules/maven-classifier/maven-classifier-example-consumer/src/test/java/com/baeldung/maven/classifier/consumer/FuelStationUnitTest.java new file mode 100644 index 0000000000..e04afb8276 --- /dev/null +++ b/maven-modules/maven-classifier/maven-classifier-example-consumer/src/test/java/com/baeldung/maven/classifier/consumer/FuelStationUnitTest.java @@ -0,0 +1,21 @@ +package com.baeldung.maven.classifier.consumer; + +import com.baeldung.maven.classifier.consumer.FuelStation.Zone; +import com.baeldung.maven.dependency.classifier.provider.model.Car; +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; + +class FuelStationUnitTest { + + @Test + @DisplayName("Given fuel type battery When request for refill Then Return Battery Zone") + public void givenFuelTypeBattery_whenRequestToRefill_thenReturnBatteryZone() { + FuelStation fuelStation = new FuelStation(); + Car electricCar = CarStub.ELECTRIC_CAR; + + assertEquals(Zone.BATTERY, fuelStation.refill(electricCar)); + } +} diff --git a/maven-modules/maven-classifier/maven-classifier-example-provider/pom.xml b/maven-modules/maven-classifier/maven-classifier-example-provider/pom.xml new file mode 100644 index 0000000000..12cb4fa1a2 --- /dev/null +++ b/maven-modules/maven-classifier/maven-classifier-example-provider/pom.xml @@ -0,0 +1,122 @@ + + + + 4.0.0 + + + maven-classifier + com.baeldung + 0.0.1-SNAPSHOT + + + maven-classifier-example-provider + 0.0.1-SNAPSHOT + + + 8 + 8 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.0 + + + JDK 8 + compile + + compile + + + 8 + 8 + true + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.2 + + + Arbitrary + + jar + + + arbitrary + + + + Test Jar + + test-jar + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + attach-sources + verify + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.3.2 + + + attach-javadocs + + jar + + + + + + + diff --git a/maven-modules/maven-classifier/maven-classifier-example-provider/src/main/java/com/baeldung/maven/dependency/classifier/provider/factory/CarFactory.java b/maven-modules/maven-classifier/maven-classifier-example-provider/src/main/java/com/baeldung/maven/dependency/classifier/provider/factory/CarFactory.java new file mode 100644 index 0000000000..285fec9ddc --- /dev/null +++ b/maven-modules/maven-classifier/maven-classifier-example-provider/src/main/java/com/baeldung/maven/dependency/classifier/provider/factory/CarFactory.java @@ -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; + } +} diff --git a/maven-modules/maven-classifier/maven-classifier-example-provider/src/main/java/com/baeldung/maven/dependency/classifier/provider/model/Car.java b/maven-modules/maven-classifier/maven-classifier-example-provider/src/main/java/com/baeldung/maven/dependency/classifier/provider/model/Car.java new file mode 100644 index 0000000000..93d5091f55 --- /dev/null +++ b/maven-modules/maven-classifier/maven-classifier-example-provider/src/main/java/com/baeldung/maven/dependency/classifier/provider/model/Car.java @@ -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 + } +} diff --git a/maven-modules/maven-classifier/maven-classifier-example-provider/src/main/java/com/baeldung/maven/dependency/classifier/provider/model/PowerSource.java b/maven-modules/maven-classifier/maven-classifier-example-provider/src/main/java/com/baeldung/maven/dependency/classifier/provider/model/PowerSource.java new file mode 100644 index 0000000000..3ac5d98efe --- /dev/null +++ b/maven-modules/maven-classifier/maven-classifier-example-provider/src/main/java/com/baeldung/maven/dependency/classifier/provider/model/PowerSource.java @@ -0,0 +1,5 @@ +package com.baeldung.maven.dependency.classifier.provider.model; + +public enum PowerSource { + BATTERY +} diff --git a/maven-modules/maven-classifier/maven-classifier-example-provider/src/test/java/com/baeldung/maven/dependency/classifier/provider/factory/CarFactoryUnitTest.java b/maven-modules/maven-classifier/maven-classifier-example-provider/src/test/java/com/baeldung/maven/dependency/classifier/provider/factory/CarFactoryUnitTest.java new file mode 100644 index 0000000000..36f0b36f1c --- /dev/null +++ b/maven-modules/maven-classifier/maven-classifier-example-provider/src/test/java/com/baeldung/maven/dependency/classifier/provider/factory/CarFactoryUnitTest.java @@ -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()); + } +} diff --git a/maven-modules/maven-classifier/maven-classifier-example-provider/src/test/java/com/baeldung/maven/dependency/classifier/provider/stub/CarStub.java b/maven-modules/maven-classifier/maven-classifier-example-provider/src/test/java/com/baeldung/maven/dependency/classifier/provider/stub/CarStub.java new file mode 100644 index 0000000000..54dbd1166f --- /dev/null +++ b/maven-modules/maven-classifier/maven-classifier-example-provider/src/test/java/com/baeldung/maven/dependency/classifier/provider/stub/CarStub.java @@ -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); + } +} diff --git a/maven-modules/maven-classifier/pom.xml b/maven-modules/maven-classifier/pom.xml new file mode 100644 index 0000000000..6b75f60893 --- /dev/null +++ b/maven-modules/maven-classifier/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + maven-classifier + pom + 0.0.1-SNAPSHOT + + + maven-classifier-example-consumer + maven-classifier-example-provider + + + + com.baeldung + maven-modules + 0.0.1-SNAPSHOT + + + + 8 + 8 + + + diff --git a/maven-modules/pom.xml b/maven-modules/pom.xml index 21bc0e72e1..37be581804 100644 --- a/maven-modules/pom.xml +++ b/maven-modules/pom.xml @@ -36,6 +36,7 @@ maven-surefire-plugin maven-parent-pom-resolution maven-simple + maven-classifier