BAEL-7388, Builder Pattern and Inheritance
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.builder.inheritance.withoutgenerics;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class BuilderInheritanceUnitTest {
|
||||
|
||||
@Test
|
||||
void givenNonGenericImpl_whenBuild_thenReturnObject() {
|
||||
Car car = new Car.CarBuilder().colour("red")
|
||||
.fuelType("Petrol")
|
||||
.make("Ford")
|
||||
.model("F")
|
||||
.build();
|
||||
assertEquals("red", car.getColour());
|
||||
assertEquals("Ford", car.getMake());
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.baledung.builder.inheritance.withgenerics;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.baeldung.builder.inheritance.withgenerics.Car;
|
||||
import com.baeldung.builder.inheritance.withgenerics.ElectricCar;
|
||||
|
||||
public class BuilderInheritanceUnitTest {
|
||||
|
||||
@Test
|
||||
void givenGenericImpl_whenBuild_thenReturnObject() {
|
||||
Car.Builder<?> carBuilder1 = new Car.Builder();
|
||||
Car car = carBuilder1.colour("red")
|
||||
.fuelType("Petrol")
|
||||
.make("Ford")
|
||||
.model("F")
|
||||
.build();
|
||||
|
||||
ElectricCar.Builder<?> ElectricCarBuilder = new ElectricCar.Builder();
|
||||
ElectricCar eCar = ElectricCarBuilder.make("Mercedes")
|
||||
.colour("White")
|
||||
.model("G")
|
||||
.fuelType("Electric")
|
||||
.batteryType("Lithium")
|
||||
.build();
|
||||
|
||||
assertEquals("red", car.getColour());
|
||||
assertEquals("Ford", car.getMake());
|
||||
|
||||
assertEquals("Electric", eCar.getFuelType());
|
||||
assertEquals("Lithium", eCar.getBatteryType());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user