diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/SameClassNameInDifferentPackageTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/SameClassNameInDifferentPackageTest.java new file mode 100644 index 000000000..7c6fa4e08 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/SameClassNameInDifferentPackageTest.java @@ -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 values = new HashMap(); + //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); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/SameNameForSourceAndTargetCarsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/SameNameForSourceAndTargetCarsMapper.java new file mode 100644 index 000000000..c9a59264e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/SameNameForSourceAndTargetCarsMapper.java @@ -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 carsToCarDtos(List cars); + org.mapstruct.ap.test.collection.map.targets.Cars sourceCarsToTargetCars(Cars source); +} \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/source/AnotherCar.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/source/AnotherCar.java new file mode 100644 index 000000000..0a95699e6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/source/AnotherCar.java @@ -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; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/source/Cars.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/source/Cars.java new file mode 100644 index 000000000..ab8aaef53 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/source/Cars.java @@ -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 makeToCar; + + public Map getMakeToCar() { + return makeToCar; + } + + public void setMakeToCar(Map makeToCar) { + this.makeToCar = makeToCar; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/targets/AnotherCar.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/targets/AnotherCar.java new file mode 100644 index 000000000..e15df9fb7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/targets/AnotherCar.java @@ -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; + } +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/targets/Cars.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/targets/Cars.java new file mode 100644 index 000000000..493cbc365 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/targets/Cars.java @@ -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 makeToCar; + + public Map getMakeToCar() { + return makeToCar; + } + + public void setMakeToCar(Map makeToCar) { + this.makeToCar = makeToCar; + } +}