#248 fix missing import for j.u.Date in DateToXmlGregorianCalender built-in mapping

This commit is contained in:
Andreas Gudian 2014-06-29 16:39:22 +02:00
parent ac7eb61c87
commit 2455330c9e
5 changed files with 124 additions and 2 deletions

View File

@ -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 )

View File

@ -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<String> createJaxb(String test) {
return new JAXBElement<String>( new QName( "www.mapstruct.org", "test" ), String.class, test );
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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;
}
}