forked from mapstruct/mapstruct
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mapstruct#3524 Provide tests with Lombok style super builders
- Loading branch information
1 parent
2c12e75
commit e815e3c
Showing
16 changed files
with
776 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
processor/src/test/java/org/mapstruct/ap/test/superbuilder/AbstractVehicle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.superbuilder; | ||
|
||
public abstract class AbstractVehicle { | ||
|
||
private final int amountOfTires; | ||
private final Passenger passenger; | ||
|
||
protected AbstractVehicle(AbstractVehicleBuilder<?, ?> b) { | ||
this.amountOfTires = b.amountOfTires; | ||
this.passenger = b.passenger; | ||
} | ||
|
||
public int getAmountOfTires() { | ||
return this.amountOfTires; | ||
} | ||
|
||
public Passenger getPassenger() { | ||
return this.passenger; | ||
} | ||
|
||
public abstract static class AbstractVehicleBuilder<C extends AbstractVehicle, | ||
B extends AbstractVehicleBuilder<C, B>> { | ||
|
||
private int amountOfTires; | ||
private Passenger passenger; | ||
|
||
public B amountOfTires(int amountOfTires) { | ||
this.amountOfTires = amountOfTires; | ||
return self(); | ||
} | ||
|
||
public B passenger(Passenger passenger) { | ||
this.passenger = passenger; | ||
return self(); | ||
} | ||
|
||
protected abstract B self(); | ||
|
||
public abstract C build(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
processor/src/test/java/org/mapstruct/ap/test/superbuilder/AbstractVehicleDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.superbuilder; | ||
|
||
public abstract class AbstractVehicleDto { | ||
|
||
private final int amountOfTires; | ||
|
||
public AbstractVehicleDto(int amountOfTires) { | ||
this.amountOfTires = amountOfTires; | ||
} | ||
|
||
public int getAmountOfTires() { | ||
return amountOfTires; | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
processor/src/test/java/org/mapstruct/ap/test/superbuilder/Car.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.superbuilder; | ||
|
||
public class Car extends Vehicle { | ||
|
||
private final String manufacturer; | ||
private final Passenger passenger; | ||
|
||
protected Car(CarBuilder<?, ?> b) { | ||
super( b ); | ||
this.manufacturer = b.manufacturer; | ||
this.passenger = b.passenger; | ||
} | ||
|
||
public static CarBuilder<?, ?> builder() { | ||
return new CarBuilderImpl(); | ||
} | ||
|
||
public String getManufacturer() { | ||
return this.manufacturer; | ||
} | ||
|
||
public Passenger getPassenger() { | ||
return this.passenger; | ||
} | ||
|
||
public abstract static class CarBuilder<C extends Car, B extends CarBuilder<C, B>> extends VehicleBuilder<C, B> { | ||
|
||
private String manufacturer; | ||
private Passenger passenger; | ||
|
||
public B manufacturer(String manufacturer) { | ||
this.manufacturer = manufacturer; | ||
return self(); | ||
} | ||
|
||
public B passenger(Passenger passenger) { | ||
this.passenger = passenger; | ||
return self(); | ||
} | ||
|
||
protected abstract B self(); | ||
|
||
public abstract C build(); | ||
} | ||
|
||
private static final class CarBuilderImpl extends CarBuilder<Car, CarBuilderImpl> { | ||
private CarBuilderImpl() { | ||
} | ||
|
||
protected CarBuilderImpl self() { | ||
return this; | ||
} | ||
|
||
public Car build() { | ||
return new Car( this ); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
processor/src/test/java/org/mapstruct/ap/test/superbuilder/CarDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.superbuilder; | ||
|
||
public class CarDto extends VehicleDto { | ||
|
||
private final String manufacturer; | ||
|
||
public CarDto(int amountOfTires, String manufacturer, PassengerDto passenger) { | ||
super( amountOfTires, passenger ); | ||
this.manufacturer = manufacturer; | ||
} | ||
|
||
public String getManufacturer() { | ||
return manufacturer; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
processor/src/test/java/org/mapstruct/ap/test/superbuilder/CarMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.superbuilder; | ||
|
||
import org.mapstruct.InheritInverseConfiguration; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper | ||
public interface CarMapper { | ||
|
||
CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); | ||
|
||
@Mapping(target = "amountOfTires", source = "tireCount") | ||
Car carDtoToCar(CarDto source); | ||
|
||
@InheritInverseConfiguration(name = "carDtoToCar") | ||
CarDto carToCarDto(Car source); | ||
|
||
@Mapping(target = "amountOfTires", source = "tireCount") | ||
ChainedAccessorsCar carDtoToChainedAccessorsCar(CarDto source); | ||
|
||
@InheritInverseConfiguration(name = "carDtoToChainedAccessorsCar") | ||
CarDto chainedAccessorsCarToCarDto(ChainedAccessorsCar source); | ||
|
||
@Mapping(target = "amountOfTires", source = "tireCount") | ||
InheritedAbstractCar carDtoToInheritedAbstractCar(CarDto source); | ||
|
||
@InheritInverseConfiguration(name = "carDtoToInheritedAbstractCar") | ||
CarDto inheritedAbstractCarToCarDto(InheritedAbstractCar source); | ||
|
||
@Mapping(target = "amountOfTires", source = "tireCount") | ||
@Mapping(target = "horsePower", constant = "140.5f") | ||
MuscleCar carDtoToMuscleCar(CarDto source); | ||
|
||
@InheritInverseConfiguration(name = "carDtoToMuscleCar") | ||
CarDto muscleCarToCarDto(MuscleCar source); | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
processor/src/test/java/org/mapstruct/ap/test/superbuilder/ChainedAccessorsCar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.superbuilder; | ||
|
||
public class ChainedAccessorsCar extends ChainedAccessorsVehicle { | ||
|
||
private String manufacturer; | ||
|
||
protected ChainedAccessorsCar(ChainedAccessorsCarBuilder<?, ?> b) { | ||
super( b ); | ||
this.manufacturer = b.manufacturer; | ||
} | ||
|
||
public static ChainedAccessorsCarBuilder<?, ?> builder() { | ||
return new ChainedAccessorsCarBuilderImpl(); | ||
} | ||
|
||
public String getManufacturer() { | ||
return this.manufacturer; | ||
} | ||
|
||
public ChainedAccessorsCar setManufacturer(String manufacturer) { | ||
this.manufacturer = manufacturer; | ||
return this; | ||
} | ||
|
||
public abstract static class ChainedAccessorsCarBuilder<C extends ChainedAccessorsCar, | ||
B extends ChainedAccessorsCarBuilder<C, B>> extends ChainedAccessorsVehicleBuilder<C, B> { | ||
|
||
private String manufacturer; | ||
|
||
public B manufacturer(String manufacturer) { | ||
this.manufacturer = manufacturer; | ||
return self(); | ||
} | ||
|
||
protected abstract B self(); | ||
|
||
public abstract C build(); | ||
} | ||
|
||
private static final class ChainedAccessorsCarBuilderImpl | ||
extends ChainedAccessorsCarBuilder<ChainedAccessorsCar, ChainedAccessorsCarBuilderImpl> { | ||
private ChainedAccessorsCarBuilderImpl() { | ||
} | ||
|
||
protected ChainedAccessorsCarBuilderImpl self() { | ||
return this; | ||
} | ||
|
||
public ChainedAccessorsCar build() { | ||
return new ChainedAccessorsCar( this ); | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
processor/src/test/java/org/mapstruct/ap/test/superbuilder/ChainedAccessorsVehicle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.superbuilder; | ||
|
||
public class ChainedAccessorsVehicle { | ||
private int amountOfTires; | ||
private Passenger passenger; | ||
|
||
protected ChainedAccessorsVehicle(ChainedAccessorsVehicleBuilder<?, ?> b) { | ||
this.amountOfTires = b.amountOfTires; | ||
this.passenger = b.passenger; | ||
} | ||
|
||
public static ChainedAccessorsVehicleBuilder<?, ?> builder() { | ||
return new ChainedAccessorsVehicleBuilderImpl(); | ||
} | ||
|
||
public int getAmountOfTires() { | ||
return this.amountOfTires; | ||
} | ||
|
||
public Passenger getPassenger() { | ||
return this.passenger; | ||
} | ||
|
||
public ChainedAccessorsVehicle setAmountOfTires(int amountOfTires) { | ||
this.amountOfTires = amountOfTires; | ||
return this; | ||
} | ||
|
||
public ChainedAccessorsVehicle setPassenger(Passenger passenger) { | ||
this.passenger = passenger; | ||
return this; | ||
} | ||
|
||
public abstract static class ChainedAccessorsVehicleBuilder<C extends ChainedAccessorsVehicle, | ||
B extends ChainedAccessorsVehicleBuilder<C, B>> { | ||
private int amountOfTires; | ||
private Passenger passenger; | ||
|
||
public B amountOfTires(int amountOfTires) { | ||
this.amountOfTires = amountOfTires; | ||
return self(); | ||
} | ||
|
||
public B passenger(Passenger passenger) { | ||
this.passenger = passenger; | ||
return self(); | ||
} | ||
|
||
protected abstract B self(); | ||
|
||
public abstract C build(); | ||
} | ||
|
||
private static final class ChainedAccessorsVehicleBuilderImpl | ||
extends ChainedAccessorsVehicleBuilder<ChainedAccessorsVehicle, ChainedAccessorsVehicleBuilderImpl> { | ||
private ChainedAccessorsVehicleBuilderImpl() { | ||
} | ||
|
||
protected ChainedAccessorsVehicleBuilderImpl self() { | ||
return this; | ||
} | ||
|
||
public ChainedAccessorsVehicle build() { | ||
return new ChainedAccessorsVehicle( this ); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
processor/src/test/java/org/mapstruct/ap/test/superbuilder/InheritedAbstractCar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.superbuilder; | ||
|
||
public class InheritedAbstractCar extends AbstractVehicle { | ||
|
||
private final String manufacturer; | ||
|
||
protected InheritedAbstractCar(InheritedAbstractCarBuilder<?, ?> b) { | ||
super( b ); | ||
this.manufacturer = b.manufacturer; | ||
} | ||
|
||
public static InheritedAbstractCarBuilder<?, ?> builder() { | ||
return new InheritedAbstractCarBuilderImpl(); | ||
} | ||
|
||
public String getManufacturer() { | ||
return this.manufacturer; | ||
} | ||
|
||
public abstract static class InheritedAbstractCarBuilder<C extends InheritedAbstractCar, | ||
B extends InheritedAbstractCarBuilder<C, B>> | ||
|
||
extends AbstractVehicleBuilder<C, B> { | ||
private String manufacturer; | ||
|
||
public B manufacturer(String manufacturer) { | ||
this.manufacturer = manufacturer; | ||
return self(); | ||
} | ||
|
||
protected abstract B self(); | ||
|
||
public abstract C build(); | ||
} | ||
|
||
private static final class InheritedAbstractCarBuilderImpl | ||
extends InheritedAbstractCarBuilder<InheritedAbstractCar, InheritedAbstractCarBuilderImpl> { | ||
private InheritedAbstractCarBuilderImpl() { | ||
} | ||
|
||
protected InheritedAbstractCarBuilderImpl self() { | ||
return this; | ||
} | ||
|
||
public InheritedAbstractCar build() { | ||
return new InheritedAbstractCar( this ); | ||
} | ||
} | ||
} |
Oops, something went wrong.