Skip to content

Commit 32e4a6e

Browse files
committed
Add test case with Default annotation for constructor resolution
#45
1 parent c916d22 commit 32e4a6e

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

src/test/java/org/mapstruct/intellij/MapstructCompletionTestCase.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,29 @@ public void testCarMapperReturnTargetCarDtoWithConstructorAndEmptyConstructor()
279279
);
280280
}
281281

282+
public void testCarMapperReturnTargetCarDtoWithMultipleConstructorsAndAnnotatedWithDefault() {
283+
configureByTestName();
284+
assertThat( myItems )
285+
.extracting( LookupElement::getLookupString )
286+
.containsExactlyInAnyOrder(
287+
"make",
288+
"seatCount",
289+
"manufacturingYear",
290+
"price"
291+
);
292+
293+
assertThat( myItems )
294+
.extracting( LookupElementPresentation::renderElement )
295+
.usingRecursiveFieldByFieldElementComparator()
296+
.usingElementComparatorIgnoringFields( "myIcon", "myTail" )
297+
.containsExactlyInAnyOrder(
298+
createParameter( "make", "String" ),
299+
createParameter( "seatCount", "int" ),
300+
createParameter( "manufacturingYear", "String" ),
301+
createParameter( "price", "Long" )
302+
);
303+
}
304+
282305
public void testPersonMapperReturnTargetFluentPersonDto() {
283306
configureByTestName();
284307
assertFluentPersonDtoAutoComplete();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.ap.test.complex;
7+
8+
import java.util.List;
9+
10+
import org.mapstruct.Mapper;
11+
import org.mapstruct.Mapping;
12+
import org.mapstruct.Mappings;
13+
import org.example.dto.CarDtoWithMultipleConstructorsAndAnnotatedWithDefault;
14+
import org.example.dto.PersonDto;
15+
import org.example.dto.Car;
16+
import org.example.dto.Person;
17+
18+
@Mapper
19+
public interface CarMapper {
20+
21+
@Mappings({
22+
@Mapping(source = "numberOfSeats", target = "<caret>seatCount"),
23+
@Mapping(source = "manufacturingDate", target = "manufacturingYear")
24+
})
25+
CarDtoWithMultipleConstructorsAndAnnotatedWithDefault carToCarDto(Car car);
26+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.example.dto;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
import org.example.dto.Default;
12+
13+
public class CarDtoWithMultipleConstructorsAndAnnotatedWithDefault {
14+
15+
private String make;
16+
private int seatCount;
17+
private String manufacturingYear;
18+
private Long price;
19+
20+
public CarDtoWithMultipleConstructorsAndAnnotatedWithDefault(String make, int seatCount) {
21+
}
22+
23+
@Default
24+
public CarDtoWithMultipleConstructorsAndAnnotatedWithDefault(String make, int seatCount, String manufacturingYear,
25+
Long price) {
26+
}
27+
28+
public String getMake() {
29+
return make;
30+
}
31+
32+
public int getSeatCount() {
33+
return seatCount;
34+
}
35+
36+
public String getManufacturingYear() {
37+
return manufacturingYear;
38+
}
39+
40+
public Long getPrice() {
41+
return price;
42+
}
43+
}

testData/mapping/dto/Default.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.example.dto;
7+
8+
public @interface Default {
9+
}

0 commit comments

Comments
 (0)