From 183d4c83e6f5ece2033e037532585fc8b37eb6d3 Mon Sep 17 00:00:00 2001 From: Christian Schuster Date: Thu, 15 May 2014 00:29:15 +0200 Subject: [PATCH] #169 add integration tests for repeated Mapping annotation --- integrationtest/pom.xml | 99 +++++++++++++++++-- .../mapstruct/itest/java8/Java8Mapper.java | 34 +++++++ .../org/mapstruct/itest/java8/Source.java | 43 ++++++++ .../org/mapstruct/itest/java8/Target.java | 43 ++++++++ .../itest/java8/Java8MapperTest.java | 55 +++++++++++ 5 files changed, 268 insertions(+), 6 deletions(-) create mode 100644 integrationtest/src/main/java/org/mapstruct/itest/java8/Java8Mapper.java create mode 100644 integrationtest/src/main/java/org/mapstruct/itest/java8/Source.java create mode 100644 integrationtest/src/main/java/org/mapstruct/itest/java8/Target.java create mode 100644 integrationtest/src/test/java/org/mapstruct/itest/java8/Java8MapperTest.java diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index a9b11fb8d..b8b86d279 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -34,12 +34,6 @@ MapStruct Integration Test - - ${project.groupId} - mapstruct - provided - - junit junit @@ -217,4 +211,97 @@ + + + + jdk-lt-8 + + [,1.8) + + + + ${project.groupId} + mapstruct + provided + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + compile + + + **/java8/ + + + + compile + + + + default-testCompile + test-compile + + + **/java8/ + + + + testCompile + + + + + + org.bsc.maven + maven-processor-plugin + + + process + generate-sources + + + **/java8/ + + + + process + + + + + + + + + jdk-geq-8 + + 1.8 + + + + ${project.groupId} + mapstruct-jdk8 + provided + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + diff --git a/integrationtest/src/main/java/org/mapstruct/itest/java8/Java8Mapper.java b/integrationtest/src/main/java/org/mapstruct/itest/java8/Java8Mapper.java new file mode 100644 index 000000000..2e787a4d6 --- /dev/null +++ b/integrationtest/src/main/java/org/mapstruct/itest/java8/Java8Mapper.java @@ -0,0 +1,34 @@ +/** + * 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.itest.java8; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Java8Mapper { + + Java8Mapper INSTANCE = Mappers.getMapper( Java8Mapper.class ); + + @Mapping(source = "firstName", target = "givenName") + @Mapping(source = "lastName", target = "surname") + Target sourceToTarget(Source source); +} diff --git a/integrationtest/src/main/java/org/mapstruct/itest/java8/Source.java b/integrationtest/src/main/java/org/mapstruct/itest/java8/Source.java new file mode 100644 index 000000000..b7b4e7571 --- /dev/null +++ b/integrationtest/src/main/java/org/mapstruct/itest/java8/Source.java @@ -0,0 +1,43 @@ +/** + * 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.itest.java8; + +public class Source { + + private String firstName; + + private String lastName; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } +} diff --git a/integrationtest/src/main/java/org/mapstruct/itest/java8/Target.java b/integrationtest/src/main/java/org/mapstruct/itest/java8/Target.java new file mode 100644 index 000000000..3bc23f750 --- /dev/null +++ b/integrationtest/src/main/java/org/mapstruct/itest/java8/Target.java @@ -0,0 +1,43 @@ +/** + * 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.itest.java8; + +public class Target { + + private String givenName; + + private String surname; + + public String getGivenName() { + return givenName; + } + + public void setGivenName(String givenName) { + this.givenName = givenName; + } + + public String getSurname() { + return surname; + } + + public void setSurname(String surname) { + this.surname = surname; + } +} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/java8/Java8MapperTest.java b/integrationtest/src/test/java/org/mapstruct/itest/java8/Java8MapperTest.java new file mode 100644 index 000000000..ec306b540 --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/java8/Java8MapperTest.java @@ -0,0 +1,55 @@ +/** + * 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.itest.java8; + +import static org.fest.assertions.Assertions.assertThat; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Test; + +/** + * Test for generation of Java8 based mapper implementations. + * + * @author Christian Schuster + */ +public class Java8MapperTest { + + @Deployment + public static JavaArchive createDeployment() { + return ShrinkWrap.create( JavaArchive.class ) + .addPackage( Java8Mapper.class.getPackage() ); + } + + @Test + public void shouldMapWithRepeatedMappingAnnotation() { + Java8Mapper mapper = Java8Mapper.INSTANCE; + + Source source = new Source(); + source.setFirstName( "firstname" ); + source.setLastName( "lastname" ); + + Target target = mapper.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getGivenName() ).isEqualTo( source.getFirstName() ); + assertThat( target.getSurname() ).isEqualTo( source.getLastName() ); + } +}