mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#119 Formatting
This commit is contained in:
parent
859c51368d
commit
fd3aa63e2d
@ -142,7 +142,7 @@
|
||||
<groupId>org.bsc.maven</groupId>
|
||||
<artifactId>maven-processor-plugin</artifactId>
|
||||
<configuration>
|
||||
<defaultOutputDirectory>${project.build.directory}/generated-sources</defaultOutputDirectory>
|
||||
<defaultOutputDirectory>${project.build.directory}/generated-sources/mapstruct</defaultOutputDirectory>
|
||||
<processors>
|
||||
<processor>org.mapstruct.ap.MappingProcessor</processor>
|
||||
</processors>
|
||||
|
@ -21,6 +21,7 @@ package org.mapstruct.itest.jaxb;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
|
||||
import org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory;
|
||||
|
||||
/**
|
||||
@ -37,12 +38,13 @@ public class JaxbMapper {
|
||||
* the proper factory method for Lists
|
||||
*
|
||||
* @param orderDetailsDescriptions
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<JAXBElement<String>> toJaxbList( List<String> orderDetailsDescriptions ) {
|
||||
List<JAXBElement<String>> toJaxbList(List<String> orderDetailsDescriptions) {
|
||||
|
||||
List<JAXBElement<String>> result = new ArrayList<JAXBElement<String>>();
|
||||
for (String orderDetailDescription : orderDetailsDescriptions) {
|
||||
for ( String orderDetailDescription : orderDetailsDescriptions ) {
|
||||
result.add( of.createOrderDetailsTypeDescription( orderDetailDescription ) );
|
||||
}
|
||||
return result;
|
||||
|
@ -21,7 +21,6 @@ package org.mapstruct.itest.jaxb;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class OrderDetailsDto {
|
||||
@ -34,7 +33,7 @@ public class OrderDetailsDto {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName( String name ) {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ -42,7 +41,7 @@ public class OrderDetailsDto {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription( List<String> description ) {
|
||||
public void setDescription(List<String> description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@ -50,7 +49,7 @@ public class OrderDetailsDto {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus( OrderStatusDto status ) {
|
||||
public void setStatus(OrderStatusDto status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ package org.mapstruct.itest.jaxb;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class OrderDto {
|
||||
@ -37,7 +36,7 @@ public class OrderDto {
|
||||
return orderNumber;
|
||||
}
|
||||
|
||||
public void setOrderNumber( Long orderNumber ) {
|
||||
public void setOrderNumber(Long orderNumber) {
|
||||
this.orderNumber = orderNumber;
|
||||
}
|
||||
|
||||
@ -45,7 +44,7 @@ public class OrderDto {
|
||||
return orderDate;
|
||||
}
|
||||
|
||||
public void setOrderDate( Date orderDate ) {
|
||||
public void setOrderDate(Date orderDate) {
|
||||
this.orderDate = orderDate;
|
||||
}
|
||||
|
||||
@ -53,7 +52,7 @@ public class OrderDto {
|
||||
return orderDetails;
|
||||
}
|
||||
|
||||
public void setOrderDetails( OrderDetailsDto orderDetails ) {
|
||||
public void setOrderDetails(OrderDetailsDto orderDetails) {
|
||||
this.orderDetails = orderDetails;
|
||||
}
|
||||
|
||||
@ -61,7 +60,7 @@ public class OrderDto {
|
||||
return shippingAddress;
|
||||
}
|
||||
|
||||
public void setShippingAddress( ShippingAddressDto shippingAddress ) {
|
||||
public void setShippingAddress(ShippingAddressDto shippingAddress) {
|
||||
this.shippingAddress = shippingAddress;
|
||||
}
|
||||
|
||||
|
@ -19,14 +19,13 @@
|
||||
package org.mapstruct.itest.jaxb;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public enum OrderStatusDto {
|
||||
|
||||
ORDERED("small"),
|
||||
PROCESSED("medium"),
|
||||
DELIVERED("large");
|
||||
ORDERED( "small" ),
|
||||
PROCESSED( "medium" ),
|
||||
DELIVERED( "large" );
|
||||
private final String value;
|
||||
|
||||
OrderStatusDto(String v) {
|
||||
@ -38,12 +37,12 @@ public enum OrderStatusDto {
|
||||
}
|
||||
|
||||
public static OrderStatusDto fromValue(String v) {
|
||||
for (OrderStatusDto c: OrderStatusDto.values()) {
|
||||
for ( OrderStatusDto c : OrderStatusDto.values() ) {
|
||||
if ( c.value.equals( v ) ) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(v);
|
||||
throw new IllegalArgumentException( v );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
package org.mapstruct.itest.jaxb;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class ShippingAddressDto {
|
||||
@ -33,7 +32,7 @@ public class ShippingAddressDto {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet( String street ) {
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
@ -41,7 +40,7 @@ public class ShippingAddressDto {
|
||||
return houseNumber;
|
||||
}
|
||||
|
||||
public void setHouseNumber( String houseNumber ) {
|
||||
public void setHouseNumber(String houseNumber) {
|
||||
this.houseNumber = houseNumber;
|
||||
}
|
||||
|
||||
@ -49,7 +48,7 @@ public class ShippingAddressDto {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity( String city ) {
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
@ -57,7 +56,7 @@ public class ShippingAddressDto {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry( String country ) {
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
|
@ -28,25 +28,32 @@ import org.mapstruct.itest.jaxb.xsd.test2.ShippingAddressType;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Mapper(uses = { org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory.class,
|
||||
org.mapstruct.itest.jaxb.xsd.test2.ObjectFactory.class,
|
||||
JaxbMapper.class })
|
||||
public interface SourceTargetMapper {
|
||||
@Mapper(uses = {
|
||||
org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory.class,
|
||||
org.mapstruct.itest.jaxb.xsd.test2.ObjectFactory.class,
|
||||
JaxbMapper.class
|
||||
})
|
||||
public interface SourceTargetMapper {
|
||||
|
||||
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
|
||||
|
||||
// source 2 target methods
|
||||
OrderDto sourceToTarget(OrderType source);
|
||||
|
||||
OrderDetailsDto detailsToDto(OrderDetailsType source);
|
||||
|
||||
OrderStatusDto statusToDto(OrderStatusType source);
|
||||
|
||||
ShippingAddressDto shippingAddressToDto(ShippingAddressType source);
|
||||
|
||||
// target 2 source methods
|
||||
OrderType targetToSource(OrderDto target);
|
||||
|
||||
OrderDetailsType dtoToDetails(OrderDetailsDto target);
|
||||
|
||||
OrderStatusType dtoToStatus(OrderStatusDto target);
|
||||
|
||||
ShippingAddressType dtoToShippingAddress(ShippingAddressDto source);
|
||||
}
|
||||
|
@ -32,11 +32,11 @@ import org.jboss.arquillian.container.test.api.Deployment;
|
||||
import org.jboss.arquillian.testng.Arquillian;
|
||||
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
||||
import org.jboss.shrinkwrap.api.spec.JavaArchive;
|
||||
import org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory;
|
||||
import org.mapstruct.itest.jaxb.xsd.test1.OrderType;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory;
|
||||
import org.mapstruct.itest.jaxb.xsd.test1.OrderType;
|
||||
|
||||
/**
|
||||
* Test for generation of JAXB based mapper implementations.
|
||||
@ -48,9 +48,9 @@ public class JaxbBasedMapperTest extends Arquillian {
|
||||
@Deployment
|
||||
public static JavaArchive createDeployment() {
|
||||
return ShrinkWrap.create( JavaArchive.class )
|
||||
.addPackage( SourceTargetMapper.class.getPackage() )
|
||||
.addPackage( org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory.class.getPackage() )
|
||||
.addPackage( org.mapstruct.itest.jaxb.xsd.test2.ObjectFactory.class.getPackage() );
|
||||
.addPackage( SourceTargetMapper.class.getPackage() )
|
||||
.addPackage( org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory.class.getPackage() )
|
||||
.addPackage( org.mapstruct.itest.jaxb.xsd.test2.ObjectFactory.class.getPackage() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -67,7 +67,7 @@ public class JaxbBasedMapperTest extends Arquillian {
|
||||
source1.getShippingAddress().setHouseNumber( "11a" );
|
||||
source1.getShippingAddress().setStreet( "Awesome rd" );
|
||||
source1.getShippingAddress().setCountry( "USA" );
|
||||
source1.getOrderDetails().setDescription( new ArrayList() );
|
||||
source1.getOrderDetails().setDescription( new ArrayList<String>() );
|
||||
source1.getOrderDetails().setName( "Shopping list for a Mapper" );
|
||||
source1.getOrderDetails().getDescription().add( "1 MapStruct" );
|
||||
source1.getOrderDetails().getDescription().add( "3 Lines of Code" );
|
||||
@ -88,23 +88,27 @@ public class JaxbBasedMapperTest extends Arquillian {
|
||||
assertThat( source2.getOrderNumber() ).isEqualTo( source1.getOrderNumber() );
|
||||
assertThat( source2.getOrderDate() ).isEqualTo( source1.getOrderDate() );
|
||||
assertThat( source2.getOrderDetails().getDescription().size() ).isEqualTo(
|
||||
source1.getOrderDetails().getDescription().size() );
|
||||
source1.getOrderDetails().getDescription().size()
|
||||
);
|
||||
assertThat( source2.getOrderDetails().getDescription().get( 0 ) ).isEqualTo(
|
||||
source1.getOrderDetails().getDescription().get( 0 ) );
|
||||
source1.getOrderDetails().getDescription().get( 0 )
|
||||
);
|
||||
assertThat( source2.getOrderDetails().getDescription().get( 1 ) ).isEqualTo(
|
||||
source1.getOrderDetails().getDescription().get( 1 ) );
|
||||
source1.getOrderDetails().getDescription().get( 1 )
|
||||
);
|
||||
assertThat( source2.getOrderDetails().getDescription().get( 2 ) ).isEqualTo(
|
||||
source1.getOrderDetails().getDescription().get( 2 ) );
|
||||
source1.getOrderDetails().getDescription().get( 2 )
|
||||
);
|
||||
assertThat( source2.getOrderDetails().getName() ).isEqualTo( source1.getOrderDetails().getName() );
|
||||
assertThat( source2.getOrderDetails().getStatus() ).isEqualTo( source1.getOrderDetails().getStatus() );
|
||||
}
|
||||
|
||||
private Date createDate( String date ) throws ParseException {
|
||||
private Date createDate(String date) throws ParseException {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat( "dd-M-yyyy hh:mm:ss" );
|
||||
return sdf.parse( date );
|
||||
}
|
||||
|
||||
private String toXml( JAXBElement element ) throws JAXBException {
|
||||
private String toXml(JAXBElement<?> element) throws JAXBException {
|
||||
JAXBContext jc = JAXBContext.newInstance( element.getValue().getClass() );
|
||||
Marshaller marshaller = jc.createMarshaller();
|
||||
marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
|
||||
|
Loading…
x
Reference in New Issue
Block a user