mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
remove builtin methods; remove test which is not needed anymore
This commit is contained in:
parent
c5dc2ccb92
commit
5fd0c3e3d4
@ -1,69 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2012-2016 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.internal.model.source.builtin;
|
|
||||||
|
|
||||||
import static org.mapstruct.ap.internal.util.Collections.asSet;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.common.Parameter;
|
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
|
||||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Filip Hrisafov
|
|
||||||
*/
|
|
||||||
public class DateToSqlDate extends BuiltInMethod {
|
|
||||||
|
|
||||||
private final Parameter parameter;
|
|
||||||
private final Type returnType;
|
|
||||||
private final Set<Type> importTypes;
|
|
||||||
|
|
||||||
public DateToSqlDate(TypeFactory typeFactory) {
|
|
||||||
this.parameter = new Parameter( "date", typeFactory.getType( Date.class ) );
|
|
||||||
this.returnType = typeFactory.getType( java.sql.Date.class );
|
|
||||||
|
|
||||||
this.importTypes = asSet(
|
|
||||||
parameter.getType()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doTypeVarsMatch(Type parameter, Type returnType) {
|
|
||||||
//We must make sure that there is only a match when the types are equal. The reason for this is to avoid
|
|
||||||
//ambiguous problems, when the return type is java.util.Date
|
|
||||||
return getReturnType().equals( returnType );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Type> getImportTypes() {
|
|
||||||
return importTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Parameter getParameter() {
|
|
||||||
return parameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Type getReturnType() {
|
|
||||||
return returnType;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2012-2016 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.internal.model.source.builtin;
|
|
||||||
|
|
||||||
import static org.mapstruct.ap.internal.util.Collections.asSet;
|
|
||||||
|
|
||||||
import java.sql.Time;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.common.Parameter;
|
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
|
||||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Filip Hrisafov
|
|
||||||
*/
|
|
||||||
public class DateToSqlTime extends BuiltInMethod {
|
|
||||||
|
|
||||||
private final Parameter parameter;
|
|
||||||
private final Type returnType;
|
|
||||||
private final Set<Type> importTypes;
|
|
||||||
|
|
||||||
public DateToSqlTime(TypeFactory typeFactory) {
|
|
||||||
this.parameter = new Parameter( "date", typeFactory.getType( Date.class ) );
|
|
||||||
this.returnType = typeFactory.getType( Time.class );
|
|
||||||
|
|
||||||
this.importTypes = asSet(
|
|
||||||
parameter.getType(),
|
|
||||||
returnType
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doTypeVarsMatch(Type parameter, Type returnType) {
|
|
||||||
//We must make sure that there is only a match when the types are equal. The reason for this is to avoid
|
|
||||||
//ambiguous problems, when the return type is java.util.Date
|
|
||||||
return getReturnType().equals( returnType );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Type> getImportTypes() {
|
|
||||||
return importTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Parameter getParameter() {
|
|
||||||
return parameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Type getReturnType() {
|
|
||||||
return returnType;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2012-2016 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.internal.model.source.builtin;
|
|
||||||
|
|
||||||
import static org.mapstruct.ap.internal.util.Collections.asSet;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.common.Parameter;
|
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
|
||||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Filip Hrisafov
|
|
||||||
*/
|
|
||||||
public class DateToSqlTimestamp extends BuiltInMethod {
|
|
||||||
|
|
||||||
private final Parameter parameter;
|
|
||||||
private final Type returnType;
|
|
||||||
private final Set<Type> importTypes;
|
|
||||||
|
|
||||||
public DateToSqlTimestamp(TypeFactory typeFactory) {
|
|
||||||
this.parameter = new Parameter( "date", typeFactory.getType( Date.class ) );
|
|
||||||
this.returnType = typeFactory.getType( Timestamp.class );
|
|
||||||
|
|
||||||
this.importTypes = asSet(
|
|
||||||
parameter.getType(),
|
|
||||||
returnType
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doTypeVarsMatch(Type parameter, Type returnType) {
|
|
||||||
//We must make sure that there is only a match when the types are equal. The reason for this is to avoid
|
|
||||||
//ambiguous problems, when the return type is java.util.Date
|
|
||||||
return getReturnType().equals( returnType );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Type> getImportTypes() {
|
|
||||||
return importTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Parameter getParameter() {
|
|
||||||
return parameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Type getReturnType() {
|
|
||||||
return returnType;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
<#--
|
|
||||||
|
|
||||||
Copyright 2012-2016 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.
|
|
||||||
|
|
||||||
-->
|
|
||||||
private java.sql.Date ${name}( Date date ) {
|
|
||||||
if ( date == null ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new java.sql.Date(date.getTime());
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
<#--
|
|
||||||
|
|
||||||
Copyright 2012-2016 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.
|
|
||||||
|
|
||||||
-->
|
|
||||||
private Time ${name}( Date date ) {
|
|
||||||
if ( date == null ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Time(date.getTime());
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
<#--
|
|
||||||
|
|
||||||
Copyright 2012-2016 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.
|
|
||||||
|
|
||||||
-->
|
|
||||||
private Timestamp ${name}( Date date ) {
|
|
||||||
if ( date == null ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Timestamp(date.getTime());
|
|
||||||
}
|
|
@ -20,8 +20,6 @@ package org.mapstruct.ap.test.builtin;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import java.sql.Time;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
@ -54,8 +52,6 @@ import org.mapstruct.ap.test.builtin.bean.DateProperty;
|
|||||||
import org.mapstruct.ap.test.builtin.bean.JaxbElementListProperty;
|
import org.mapstruct.ap.test.builtin.bean.JaxbElementListProperty;
|
||||||
import org.mapstruct.ap.test.builtin.bean.JaxbElementProperty;
|
import org.mapstruct.ap.test.builtin.bean.JaxbElementProperty;
|
||||||
import org.mapstruct.ap.test.builtin.bean.SqlDateProperty;
|
import org.mapstruct.ap.test.builtin.bean.SqlDateProperty;
|
||||||
import org.mapstruct.ap.test.builtin.bean.SqlTimeProperty;
|
|
||||||
import org.mapstruct.ap.test.builtin.bean.SqlTimestampProperty;
|
|
||||||
import org.mapstruct.ap.test.builtin.bean.StringListProperty;
|
import org.mapstruct.ap.test.builtin.bean.StringListProperty;
|
||||||
import org.mapstruct.ap.test.builtin.bean.StringProperty;
|
import org.mapstruct.ap.test.builtin.bean.StringProperty;
|
||||||
import org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty;
|
import org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty;
|
||||||
@ -66,14 +62,11 @@ import org.mapstruct.ap.test.builtin.mapper.CalendarToDateMapper;
|
|||||||
import org.mapstruct.ap.test.builtin.mapper.CalendarToStringMapper;
|
import org.mapstruct.ap.test.builtin.mapper.CalendarToStringMapper;
|
||||||
import org.mapstruct.ap.test.builtin.mapper.CalendarToXmlGregCalMapper;
|
import org.mapstruct.ap.test.builtin.mapper.CalendarToXmlGregCalMapper;
|
||||||
import org.mapstruct.ap.test.builtin.mapper.DateToCalendarMapper;
|
import org.mapstruct.ap.test.builtin.mapper.DateToCalendarMapper;
|
||||||
import org.mapstruct.ap.test.builtin.mapper.DateToSqlDateMapper;
|
|
||||||
import org.mapstruct.ap.test.builtin.mapper.DateToXmlGregCalMapper;
|
import org.mapstruct.ap.test.builtin.mapper.DateToXmlGregCalMapper;
|
||||||
import org.mapstruct.ap.test.builtin.mapper.IterableSourceTargetMapper;
|
import org.mapstruct.ap.test.builtin.mapper.IterableSourceTargetMapper;
|
||||||
import org.mapstruct.ap.test.builtin.mapper.JaxbListMapper;
|
import org.mapstruct.ap.test.builtin.mapper.JaxbListMapper;
|
||||||
import org.mapstruct.ap.test.builtin.mapper.JaxbMapper;
|
import org.mapstruct.ap.test.builtin.mapper.JaxbMapper;
|
||||||
import org.mapstruct.ap.test.builtin.mapper.MapSourceTargetMapper;
|
import org.mapstruct.ap.test.builtin.mapper.MapSourceTargetMapper;
|
||||||
import org.mapstruct.ap.test.builtin.mapper.SqlTimeMapper;
|
|
||||||
import org.mapstruct.ap.test.builtin.mapper.SqlTimestampMapper;
|
|
||||||
import org.mapstruct.ap.test.builtin.mapper.StringToCalendarMapper;
|
import org.mapstruct.ap.test.builtin.mapper.StringToCalendarMapper;
|
||||||
import org.mapstruct.ap.test.builtin.mapper.StringToXmlGregCalMapper;
|
import org.mapstruct.ap.test.builtin.mapper.StringToXmlGregCalMapper;
|
||||||
import org.mapstruct.ap.test.builtin.mapper.XmlGregCalToCalendarMapper;
|
import org.mapstruct.ap.test.builtin.mapper.XmlGregCalToCalendarMapper;
|
||||||
@ -94,8 +87,6 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
|||||||
IterableTarget.class,
|
IterableTarget.class,
|
||||||
MapTarget.class,
|
MapTarget.class,
|
||||||
SqlDateProperty.class,
|
SqlDateProperty.class,
|
||||||
SqlTimeProperty.class,
|
|
||||||
SqlTimestampProperty.class,
|
|
||||||
CalendarProperty.class,
|
CalendarProperty.class,
|
||||||
DateProperty.class,
|
DateProperty.class,
|
||||||
JaxbElementListProperty.class,
|
JaxbElementListProperty.class,
|
||||||
@ -111,9 +102,6 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
|||||||
CalendarToXmlGregCalMapper.class,
|
CalendarToXmlGregCalMapper.class,
|
||||||
DateToCalendarMapper.class,
|
DateToCalendarMapper.class,
|
||||||
DateToXmlGregCalMapper.class,
|
DateToXmlGregCalMapper.class,
|
||||||
DateToSqlDateMapper.class,
|
|
||||||
SqlTimeMapper.class,
|
|
||||||
SqlTimestampMapper.class,
|
|
||||||
IterableSourceTargetMapper.class,
|
IterableSourceTargetMapper.class,
|
||||||
JaxbListMapper.class,
|
JaxbListMapper.class,
|
||||||
JaxbMapper.class,
|
JaxbMapper.class,
|
||||||
@ -270,7 +258,7 @@ public class BuiltInTest {
|
|||||||
|
|
||||||
DateProperty target = CalendarToDateMapper.INSTANCE.map( source );
|
DateProperty target = CalendarToDateMapper.INSTANCE.map( source );
|
||||||
assertThat( target ).isNotNull();
|
assertThat( target ).isNotNull();
|
||||||
assertThat( target.getProp() ).isNotNull().isInstanceOf( Date.class );
|
assertThat( target.getProp() ).isNotNull();
|
||||||
assertThat( target.getProp() ).isEqualTo( createCalendar( "02.03.1999" ).getTime() );
|
assertThat( target.getProp() ).isEqualTo( createCalendar( "02.03.1999" ).getTime() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,89 +349,6 @@ public class BuiltInTest {
|
|||||||
assertThat( target.getProp() ).isEqualTo( createCalendar( "02.03.1999" ) );
|
assertThat( target.getProp() ).isEqualTo( createCalendar( "02.03.1999" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldApplyBuiltInOnDateToSqlDate() throws ParseException {
|
|
||||||
assertThat( DateToSqlDateMapper.INSTANCE.toTargetWithSqlDate( null ) ).isNull();
|
|
||||||
DateProperty source = new DateProperty();
|
|
||||||
source.setProp( createDate( "31-08-1982 10:20:56" ) );
|
|
||||||
|
|
||||||
SqlDateProperty target = DateToSqlDateMapper.INSTANCE.toTargetWithSqlDate( source );
|
|
||||||
|
|
||||||
assertThat( target ).isNotNull();
|
|
||||||
assertThat( target.getProp() ).isNotNull().isInstanceOf( java.sql.Date.class );
|
|
||||||
assertThat( target.getProp().toString() ).isEqualTo( "1982-08-31" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldUseSqlDateWhenMappingToDate() throws ParseException {
|
|
||||||
assertThat( DateToSqlDateMapper.INSTANCE.fromSqlDate( null ) ).isNull();
|
|
||||||
|
|
||||||
SqlDateProperty source = new SqlDateProperty();
|
|
||||||
source.setProp( new java.sql.Date( createDate( "31-08-1982 10:20:56" ).getTime() ) );
|
|
||||||
|
|
||||||
DateProperty target = DateToSqlDateMapper.INSTANCE.fromSqlDate( source );
|
|
||||||
assertThat( target ).isNotNull();
|
|
||||||
assertThat( target.getProp() ).isNotNull();
|
|
||||||
assertThat( target.getProp().toString() ).isEqualTo( "1982-08-31" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldApplyBuiltInOnDateToSqlTime() throws ParseException {
|
|
||||||
SqlTimeMapper mapper = SqlTimeMapper.INSTANCE;
|
|
||||||
assertThat( mapper.map( null ) ).isNull();
|
|
||||||
DateProperty source = new DateProperty();
|
|
||||||
source.setProp( createDate( "31-08-1982 10:20:56" ) );
|
|
||||||
|
|
||||||
SqlTimeProperty target = mapper.map( source );
|
|
||||||
|
|
||||||
assertThat( target ).isNotNull();
|
|
||||||
assertThat( target.getProp() ).isNotNull();
|
|
||||||
assertThat( target.getProp().toString() ).isEqualTo( "10:20:56" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldUseSqlTimeWhenMappingToDate() throws ParseException {
|
|
||||||
SqlTimeMapper mapper = SqlTimeMapper.INSTANCE;
|
|
||||||
assertThat( mapper.fromTime( null ) ).isNull();
|
|
||||||
|
|
||||||
SqlTimeProperty source = new SqlTimeProperty();
|
|
||||||
source.setProp( new Time( createDate( "31-08-1982 10:20:56" ).getTime() ) );
|
|
||||||
|
|
||||||
DateProperty target = mapper.fromTime( source );
|
|
||||||
assertThat( target ).isNotNull();
|
|
||||||
assertThat( target.getProp() ).isNotNull();
|
|
||||||
assertThat( target.getProp().toString() ).isEqualTo( "10:20:56" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldApplyBuiltInOnDateToSqlTimestamp() throws ParseException {
|
|
||||||
SqlTimestampMapper mapper = SqlTimestampMapper.INSTANCE;
|
|
||||||
assertThat( mapper.map( null ) ).isNull();
|
|
||||||
DateProperty source = new DateProperty();
|
|
||||||
source.setProp( createDate( "31-08-1982 10:20:56" ) );
|
|
||||||
|
|
||||||
SqlTimestampProperty target = mapper.map( source );
|
|
||||||
|
|
||||||
assertThat( target ).isNotNull();
|
|
||||||
assertThat( target.getProp() ).isNotNull();
|
|
||||||
assertThat( target.getProp().toString() ).isEqualTo( "1982-08-31 10:20:56.0" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldUseSqlTimestampWhenMappingToDate() throws ParseException {
|
|
||||||
SqlTimestampMapper mapper = SqlTimestampMapper.INSTANCE;
|
|
||||||
assertThat( mapper.fromTimestamp( null ) ).isNull();
|
|
||||||
|
|
||||||
SqlTimestampProperty source = new SqlTimestampProperty();
|
|
||||||
source.setProp( new Timestamp( createDate( "31-08-1982 10:20:56" ).getTime() ) );
|
|
||||||
|
|
||||||
DateProperty target = mapper.fromTimestamp( source );
|
|
||||||
assertThat( target ).isNotNull();
|
|
||||||
assertThat( target.getProp() ).isNotNull();
|
|
||||||
assertThat( target.getProp().toString() ).isEqualTo( "1982-08-31 10:20:56.0" );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private JAXBElement<String> createJaxb(String test) {
|
private JAXBElement<String> createJaxb(String test) {
|
||||||
return new JAXBElement<String>( new QName( "www.mapstruct.org", "test" ), String.class, test );
|
return new JAXBElement<String>( new QName( "www.mapstruct.org", "test" ), String.class, test );
|
||||||
}
|
}
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2012-2016 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.bean;
|
|
||||||
|
|
||||||
import java.sql.Time;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Filip Hrisafov
|
|
||||||
*/
|
|
||||||
public class SqlTimeProperty {
|
|
||||||
|
|
||||||
private Time prop;
|
|
||||||
|
|
||||||
public Time getProp() {
|
|
||||||
return prop;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProp(Time prop) {
|
|
||||||
this.prop = prop;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2012-2016 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.bean;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Filip Hrisafov
|
|
||||||
*/
|
|
||||||
public class SqlTimestampProperty {
|
|
||||||
|
|
||||||
private Timestamp prop;
|
|
||||||
|
|
||||||
public Timestamp getProp() {
|
|
||||||
return prop;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProp(Timestamp prop) {
|
|
||||||
this.prop = prop;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2012-2016 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.mapper;
|
|
||||||
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.ap.test.builtin.bean.DateProperty;
|
|
||||||
import org.mapstruct.ap.test.builtin.bean.SqlDateProperty;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Andreas Gudian
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface DateToSqlDateMapper {
|
|
||||||
|
|
||||||
DateToSqlDateMapper INSTANCE = Mappers.getMapper( DateToSqlDateMapper.class );
|
|
||||||
|
|
||||||
SqlDateProperty toTargetWithSqlDate(DateProperty source);
|
|
||||||
|
|
||||||
DateProperty fromSqlDate(SqlDateProperty source);
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2012-2016 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.mapper;
|
|
||||||
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.ap.test.builtin.bean.DateProperty;
|
|
||||||
import org.mapstruct.ap.test.builtin.bean.SqlTimeProperty;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Andreas Gudian
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface SqlTimeMapper {
|
|
||||||
|
|
||||||
SqlTimeMapper INSTANCE = Mappers.getMapper( SqlTimeMapper.class );
|
|
||||||
|
|
||||||
SqlTimeProperty map(DateProperty source);
|
|
||||||
|
|
||||||
DateProperty fromTime(SqlTimeProperty source);
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2012-2016 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.mapper;
|
|
||||||
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.ap.test.builtin.bean.DateProperty;
|
|
||||||
import org.mapstruct.ap.test.builtin.bean.SqlTimestampProperty;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Andreas Gudian
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface SqlTimestampMapper {
|
|
||||||
|
|
||||||
SqlTimestampMapper INSTANCE = Mappers.getMapper( SqlTimestampMapper.class );
|
|
||||||
|
|
||||||
SqlTimestampProperty map(DateProperty source);
|
|
||||||
|
|
||||||
DateProperty fromTimestamp(SqlTimestampProperty source);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user