Demonstrates issue #394

This commit is contained in:
Dilip Krishnan 2014-12-22 16:18:51 -06:00 committed by sjaakd
parent 883ccf92cd
commit 555095e85c
6 changed files with 287 additions and 0 deletions

View File

@ -0,0 +1,61 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.collection.map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.test.collection.map.source.AnotherCar;
import org.mapstruct.ap.test.collection.map.source.Cars;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import java.util.HashMap;
import java.util.Map;
import static org.fest.assertions.Assertions.assertThat;
@WithClasses({ SameNameForSourceAndTargetCarsMapper.class, Cars.class, org.mapstruct.ap.test.collection.map.targets.Cars
.class, AnotherCar.class, org.mapstruct.ap.test.collection.map.targets.AnotherCar.class })
@IssueKey("394")
@RunWith(AnnotationProcessorTestRunner.class)
public class SameClassNameInDifferentPackageTest {
@Test
public void shouldCreateMapMethodImplementation() {
Map<String, AnotherCar> values = new HashMap<String, AnotherCar>();
//given
AnotherCar honda = new AnotherCar(
"Honda",
2
);
AnotherCar toyota = new AnotherCar(
"Toyota",
2
);
values.put("Honda", honda);
values.put("Toyota", toyota);
Cars cars = new Cars();
cars.setMakeToCar(values);
org.mapstruct.ap.test.collection.map.targets.Cars targetCars = SameNameForSourceAndTargetCarsMapper.INSTANCE
.sourceCarsToTargetCars(cars);
assertThat(targetCars).isNotNull();
assertThat(targetCars.getMakeToCar()).hasSize(2);
}
}

View File

@ -0,0 +1,42 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.collection.map;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.ap.test.collection.map.source.Cars;
import org.mapstruct.ap.test.collection.map.targets.AnotherCar;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface SameNameForSourceAndTargetCarsMapper {
SameNameForSourceAndTargetCarsMapper INSTANCE = Mappers.getMapper(SameNameForSourceAndTargetCarsMapper.class);
@Mappings({
@Mapping(source = "numberOfSeats", target = "seatCount")
})
AnotherCar carToCarDto(org.mapstruct.ap.test.collection.map.source.AnotherCar car);
List<AnotherCar> carsToCarDtos(List<org.mapstruct.ap.test.collection.map.source.AnotherCar> cars);
org.mapstruct.ap.test.collection.map.targets.Cars sourceCarsToTargetCars(Cars source);
}

View File

@ -0,0 +1,59 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.collection.map.source;
public class AnotherCar {
private String make;
private int numberOfSeats;
private int price;
public AnotherCar() {
}
public AnotherCar(String make, int numberOfSeats) {
this.make = make;
this.numberOfSeats = numberOfSeats;
}
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
public int getNumberOfSeats() {
return numberOfSeats;
}
public void setNumberOfSeats(int numberOfSeats) {
this.numberOfSeats = numberOfSeats;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}

View File

@ -0,0 +1,33 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.collection.map.source;
import java.util.Map;
public class Cars {
private Map<String, AnotherCar> makeToCar;
public Map<String, AnotherCar> getMakeToCar() {
return makeToCar;
}
public void setMakeToCar(Map<String, AnotherCar> makeToCar) {
this.makeToCar = makeToCar;
}
}

View File

@ -0,0 +1,59 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.collection.map.targets;
public class AnotherCar {
private String make;
private int seatCount;
private Long price;
public AnotherCar() {
}
public AnotherCar(String make, int seatCount) {
this.make = make;
this.seatCount = seatCount;
}
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
public int getSeatCount() {
return seatCount;
}
public void setSeatCount(int seatCount) {
this.seatCount = seatCount;
}
public Long getPrice() {
return price;
}
public void setPrice(Long price) {
this.price = price;
}
}

View File

@ -0,0 +1,33 @@
/**
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.collection.map.targets;
import java.util.Map;
public class Cars {
private Map<String, AnotherCar> makeToCar;
public Map<String, AnotherCar> getMakeToCar() {
return makeToCar;
}
public void setMakeToCar(Map<String, AnotherCar> makeToCar) {
this.makeToCar = makeToCar;
}
}