diff --git a/processor/src/main/java/org/mapstruct/ap/model/source/builtin/DateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/model/source/builtin/DateToXmlGregorianCalendar.java index 08b926311..202fcd730 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/source/builtin/DateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/model/source/builtin/DateToXmlGregorianCalendar.java @@ -21,6 +21,7 @@ package org.mapstruct.ap.model.source.builtin; import java.util.Date; import java.util.GregorianCalendar; import java.util.Set; + import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; @@ -46,6 +47,7 @@ public class DateToXmlGregorianCalendar extends BuiltInMethod { this.importTypes = asSet( returnType, + parameter.getType(), typeFactory.getType( GregorianCalendar.class ), typeFactory.getType( DatatypeFactory.class ), typeFactory.getType( DatatypeConfigurationException.class ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java index 4e368252d..e932d90e5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.test.builtin; -import static org.fest.assertions.Assertions.assertThat; - import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -42,9 +40,12 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.fest.assertions.Assertions.assertThat; + /** * Test for the generation of built-in mapping methods. * @@ -121,6 +122,17 @@ public class BuiltInTest { assertThat( target.getExample().get( "TEST" ) ).isEqualTo( "1999-03-02+01:00" ); } + @Test + @IssueKey( "248" ) + @WithClasses( { SourceWithDate.class, TargetWithDate.class, SourceTargetWithDateMapper.class } ) + public void dateToXmlGregorianCalenderHasCorrectImports() { + assertThat( SourceTargetWithDateMapper.INSTANCE.toTargetWithDate( null ) ).isNull(); + + TargetWithDate targetWithDate = SourceTargetWithDateMapper.INSTANCE.toTargetWithDate( new SourceWithDate() ); + assertThat( targetWithDate ).isNotNull(); + assertThat( targetWithDate.getDate() ).isNull(); + } + private JAXBElement createJaxb(String test) { return new JAXBElement( new QName( "www.mapstruct.org", "test" ), String.class, test ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/SourceTargetWithDateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/SourceTargetWithDateMapper.java new file mode 100644 index 000000000..95c6a5c9f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/SourceTargetWithDateMapper.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.ap.test.builtin; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Andreas Gudian + * + */ +@Mapper +public interface SourceTargetWithDateMapper { + + SourceTargetWithDateMapper INSTANCE = Mappers.getMapper( SourceTargetWithDateMapper.class ); + + TargetWithDate toTargetWithDate(SourceWithDate source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/SourceWithDate.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/SourceWithDate.java new file mode 100644 index 000000000..b78a7e004 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/SourceWithDate.java @@ -0,0 +1,37 @@ +/** + * 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.builtin; + +import java.util.Date; + +/** + * @author Andreas Gudian + * + */ +public class SourceWithDate { + private Date date; + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/TargetWithDate.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/TargetWithDate.java new file mode 100644 index 000000000..f647282ff --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/TargetWithDate.java @@ -0,0 +1,37 @@ +/** + * 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.builtin; + +import javax.xml.datatype.XMLGregorianCalendar; + +/** + * @author Andreas Gudian + * + */ +public class TargetWithDate { + private XMLGregorianCalendar date; + + public XMLGregorianCalendar getDate() { + return date; + } + + public void setDate(XMLGregorianCalendar date) { + this.date = date; + } +}