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#3360 Do not report unmapped source and target properties wh…
…en result type is abstract due to runtime exception subclass exhaustive strategy
- Loading branch information
Showing
5 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Issue3360Mapper.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,34 @@ | ||
/* | ||
* 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.bugs._3360; | ||
|
||
import org.mapstruct.BeanMapping; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.ReportingPolicy; | ||
import org.mapstruct.SubclassExhaustiveStrategy; | ||
import org.mapstruct.SubclassMapping; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
@Mapper( | ||
subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION, | ||
unmappedTargetPolicy = ReportingPolicy.ERROR, | ||
unmappedSourcePolicy = ReportingPolicy.ERROR | ||
) | ||
public interface Issue3360Mapper { | ||
|
||
Issue3360Mapper INSTANCE = Mappers.getMapper( Issue3360Mapper.class ); | ||
|
||
@SubclassMapping(target = VehicleDto.Car.class, source = Vehicle.Car.class) | ||
VehicleDto map(Vehicle vehicle); | ||
|
||
@Mapping(target = "model", source = "modelName") | ||
@BeanMapping(ignoreUnmappedSourceProperties = "computedName") | ||
VehicleDto.Car map(Vehicle.Car car); | ||
} |
43 changes: 43 additions & 0 deletions
43
processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Issue3360Test.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.bugs._3360; | ||
|
||
import org.mapstruct.ap.testutil.IssueKey; | ||
import org.mapstruct.ap.testutil.ProcessorTest; | ||
import org.mapstruct.ap.testutil.WithClasses; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
@IssueKey("3360") | ||
@WithClasses({ | ||
Issue3360Mapper.class, | ||
Vehicle.class, | ||
VehicleDto.class, | ||
}) | ||
class Issue3360Test { | ||
|
||
@ProcessorTest | ||
void shouldCompileWithoutErrorsAndWarnings() { | ||
|
||
Vehicle vehicle = new Vehicle.Car( "Test", "car", 4 ); | ||
|
||
VehicleDto target = Issue3360Mapper.INSTANCE.map( vehicle ); | ||
|
||
assertThat( target.getName() ).isEqualTo( "Test" ); | ||
assertThat( target.getModel() ).isEqualTo( "car" ); | ||
assertThat( target ).isInstanceOfSatisfying( VehicleDto.Car.class, car -> { | ||
assertThat( car.getNumOfDoors() ).isEqualTo( 4 ); | ||
} ); | ||
|
||
assertThatThrownBy( () -> Issue3360Mapper.INSTANCE.map( new Vehicle.Motorbike( "Test", "bike" ) ) ) | ||
.isInstanceOf( IllegalArgumentException.class ) | ||
.hasMessage( "Not all subclasses are supported for this mapping. Missing for " + Vehicle.Motorbike.class ); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Vehicle.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,55 @@ | ||
/* | ||
* 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.bugs._3360; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
public abstract class Vehicle { | ||
|
||
private final String name; | ||
private final String modelName; | ||
|
||
protected Vehicle(String name, String modelName) { | ||
this.name = name; | ||
this.modelName = modelName; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getModelName() { | ||
return modelName; | ||
} | ||
|
||
public String getComputedName() { | ||
return null; | ||
} | ||
|
||
public static class Car extends Vehicle { | ||
|
||
private final int numOfDoors; | ||
|
||
public Car(String name, String modelName, int numOfDoors) { | ||
super( name, modelName ); | ||
this.numOfDoors = numOfDoors; | ||
} | ||
|
||
public int getNumOfDoors() { | ||
return numOfDoors; | ||
} | ||
} | ||
|
||
public static class Motorbike extends Vehicle { | ||
|
||
public Motorbike(String name, String modelName) { | ||
super( name, modelName ); | ||
} | ||
|
||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/VehicleDto.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,45 @@ | ||
/* | ||
* 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.bugs._3360; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
public abstract class VehicleDto { | ||
|
||
private String name; | ||
private String model; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getModel() { | ||
return model; | ||
} | ||
|
||
public void setModel(String model) { | ||
this.model = model; | ||
} | ||
|
||
public static class Car extends VehicleDto { | ||
|
||
private int numOfDoors; | ||
|
||
public int getNumOfDoors() { | ||
return numOfDoors; | ||
} | ||
|
||
public void setNumOfDoors(int numOfDoors) { | ||
this.numOfDoors = numOfDoors; | ||
} | ||
} | ||
|
||
} |