diff --git a/core-common/src/main/java/org/mapstruct/NullValueMapping.java b/core-common/src/main/java/org/mapstruct/NullValueMapping.java index ad7d88b69..d2d849c4d 100644 --- a/core-common/src/main/java/org/mapstruct/NullValueMapping.java +++ b/core-common/src/main/java/org/mapstruct/NullValueMapping.java @@ -31,8 +31,8 @@ import java.lang.annotation.Target; * * @author Sjaak Derksen */ -@Target( { ElementType.METHOD } ) -@Retention( RetentionPolicy.SOURCE ) +@Target({ ElementType.METHOD }) +@Retention(RetentionPolicy.SOURCE) public @interface NullValueMapping { /** diff --git a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java index 4dbf52d70..8f0883cbd 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; - import javax.lang.model.element.ExecutableElement; import javax.tools.Diagnostic; @@ -40,8 +39,8 @@ import org.mapstruct.ap.model.source.Mapping; import org.mapstruct.ap.model.source.SourceMethod; import org.mapstruct.ap.model.source.SourceReference; import org.mapstruct.ap.option.ReportingPolicy; -import org.mapstruct.ap.prism.NullValueMappingPrism; import org.mapstruct.ap.prism.CollectionMappingStrategyPrism; +import org.mapstruct.ap.prism.NullValueMappingPrism; import org.mapstruct.ap.util.Executables; import org.mapstruct.ap.util.MapperConfig; import org.mapstruct.ap.util.Strings; @@ -102,7 +101,7 @@ public class BeanMappingMethod extends MappingMethod { // mapNullToDefault NullValueMappingPrism prism = NullValueMappingPrism.getInstanceOn( method.getExecutable() ); boolean mapNullToDefault = - MapperConfig.getInstanceOn( ctx.getMapperTypeElement() ).isMapToDefault( prism ); + MapperConfig.getInstanceOn( ctx.getMapperTypeElement() ).isMapToDefault( prism ); MethodReference factoryMethod = AssignmentFactory.createFactoryMethod( method.getReturnType(), ctx ); return new BeanMappingMethod( method, propertyMappings, factoryMethod, mapNullToDefault ); @@ -182,13 +181,14 @@ public class BeanMappingMethod extends MappingMethod { ExecutableElement targetProperty = unprocessedTargetProperties.get( mapping.getTargetName() ); if ( targetProperty == null ) { ctx.getMessager().printMessage( - Diagnostic.Kind.ERROR, - String.format( "Unknown property \"%s\" in return type.", - mapping.getTargetName() - ), - method.getExecutable(), - mapping.getMirror(), - mapping.getSourceAnnotationValue() + Diagnostic.Kind.ERROR, + String.format( + "Unknown property \"%s\" in return type.", + mapping.getTargetName() + ), + method.getExecutable(), + mapping.getMirror(), + mapping.getSourceAnnotationValue() ); errorOccurred = true; } @@ -212,14 +212,14 @@ public class BeanMappingMethod extends MappingMethod { // targetProperty == null can occur: we arrived here because we want as many errors // as possible before we stop analysing propertyMapping = new PropertyMappingBuilder() - .mappingContext( ctx ) - .souceMethod( method ) - .targetAccessor( targetProperty ) - .targetPropertyName( mapping.getTargetName() ) - .sourceReference( sourceRef ) - .qualifiers( mapping.getQualifiers() ) - .dateFormat( mapping.getDateFormat() ) - .build(); + .mappingContext( ctx ) + .souceMethod( method ) + .targetAccessor( targetProperty ) + .targetPropertyName( mapping.getTargetName() ) + .sourceReference( sourceRef ) + .qualifiers( mapping.getQualifiers() ) + .dateFormat( mapping.getDateFormat() ) + .build(); handledTargets.add( mapping.getTargetName() ); unprocessedSourceParameters.remove( sourceRef.getParameter() ); } @@ -233,13 +233,13 @@ public class BeanMappingMethod extends MappingMethod { else if ( mapping.getConstant() != null && targetProperty != null ) { propertyMapping = new ConstantMappingBuilder() - .mappingContext( ctx ) - .sourceMethod( method ) - .constantExpression( "\"" + mapping.getConstant() + "\"" ) - .targetAccessor( targetProperty ) - .dateFormat( mapping.getDateFormat() ) - .qualifiers( mapping.getQualifiers() ) - .build(); + .mappingContext( ctx ) + .sourceMethod( method ) + .constantExpression( "\"" + mapping.getConstant() + "\"" ) + .targetAccessor( targetProperty ) + .dateFormat( mapping.getDateFormat() ) + .qualifiers( mapping.getQualifiers() ) + .build(); handledTargets.add( mapping.getTargetName() ); } @@ -247,11 +247,11 @@ public class BeanMappingMethod extends MappingMethod { else if ( mapping.getJavaExpression() != null && targetProperty != null ) { propertyMapping = new JavaExpressionMappingBuilder() - .mappingContext( ctx ) - .souceMethod( method ) - .javaExpression( mapping.getJavaExpression() ) - .targetAccessor( targetProperty ) - .build(); + .mappingContext( ctx ) + .souceMethod( method ) + .javaExpression( mapping.getJavaExpression() ) + .targetAccessor( targetProperty ) + .build(); handledTargets.add( mapping.getTargetName() ); } @@ -280,7 +280,7 @@ public class BeanMappingMethod extends MappingMethod { */ private void applyPropertyNameBasedMapping() { Iterator> targetProperties = - unprocessedTargetProperties.entrySet().iterator(); + unprocessedTargetProperties.entrySet().iterator(); // usually there should be only one getter; only for Boolean there may be two: isFoo() and getFoo() List candidates = new ArrayList( 2 ); @@ -312,21 +312,21 @@ public class BeanMappingMethod extends MappingMethod { Mapping mapping = method.getSingleMappingByTargetPropertyName( targetProperty.getKey() ); SourceReference sourceRef = new SourceReference.BuilderFromProperty() - .sourceParameter( sourceParameter ) - .type( ctx.getTypeFactory().getReturnType( sourceAccessor ) ) - .accessor( sourceAccessor ) - .name( targetProperty.getKey() ) - .build(); + .sourceParameter( sourceParameter ) + .type( ctx.getTypeFactory().getReturnType( sourceAccessor ) ) + .accessor( sourceAccessor ) + .name( targetProperty.getKey() ) + .build(); newPropertyMapping = new PropertyMappingBuilder() - .mappingContext( ctx ) - .souceMethod( method ) - .targetAccessor( targetProperty.getValue() ) - .targetPropertyName( targetProperty.getKey() ) - .sourceReference( sourceRef ) - .qualifiers( mapping != null ? mapping.getQualifiers() : null ) - .dateFormat( mapping != null ? mapping.getDateFormat() : null ) - .build(); + .mappingContext( ctx ) + .souceMethod( method ) + .targetAccessor( targetProperty.getValue() ) + .targetPropertyName( targetProperty.getKey() ) + .sourceReference( sourceRef ) + .qualifiers( mapping != null ? mapping.getQualifiers() : null ) + .dateFormat( mapping != null ? mapping.getDateFormat() : null ) + .build(); unprocessedSourceParameters.remove( sourceParameter ); @@ -337,11 +337,11 @@ public class BeanMappingMethod extends MappingMethod { if ( propertyMapping != null && newPropertyMapping != null ) { // TODO improve error message ctx.getMessager().printMessage( - Diagnostic.Kind.ERROR, - "Several possible source properties for target property \"" + Diagnostic.Kind.ERROR, + "Several possible source properties for target property \"" + targetProperty.getKey() + "\".", - method.getExecutable() + method.getExecutable() ); break; } @@ -361,7 +361,7 @@ public class BeanMappingMethod extends MappingMethod { private void applyParameterNameBasedMapping() { Iterator> targetProperties = - unprocessedTargetProperties.entrySet().iterator(); + unprocessedTargetProperties.entrySet().iterator(); while ( targetProperties.hasNext() ) { @@ -376,19 +376,19 @@ public class BeanMappingMethod extends MappingMethod { Mapping mapping = method.getSingleMappingByTargetPropertyName( targetProperty.getKey() ); SourceReference sourceRef = new SourceReference.BuilderFromProperty() - .sourceParameter( sourceParameter ) - .name( targetProperty.getKey() ) - .build(); + .sourceParameter( sourceParameter ) + .name( targetProperty.getKey() ) + .build(); PropertyMapping propertyMapping = new PropertyMappingBuilder() - .mappingContext( ctx ) - .souceMethod( method ) - .targetAccessor( targetProperty.getValue() ) - .targetPropertyName( targetProperty.getKey() ) - .sourceReference( sourceRef ) - .qualifiers( mapping != null ? mapping.getQualifiers() : null ) - .dateFormat( mapping != null ? mapping.getDateFormat() : null ) - .build(); + .mappingContext( ctx ) + .souceMethod( method ) + .targetAccessor( targetProperty.getValue() ) + .targetPropertyName( targetProperty.getKey() ) + .sourceReference( sourceRef ) + .qualifiers( mapping != null ? mapping.getQualifiers() : null ) + .dateFormat( mapping != null ? mapping.getDateFormat() : null ) + .build(); propertyMappings.add( propertyMapping ); targetProperties.remove(); @@ -426,7 +426,7 @@ public class BeanMappingMethod extends MappingMethod { } } - /** + /** * Returns the effective policy for reporting unmapped getReturnType properties. If explicitly set via * {@code Mapper}, this value will be returned. Otherwise the value from the corresponding processor option will * be returned. If that is not set either, the default value from {@code Mapper#unmappedTargetPolicy()} will be @@ -456,8 +456,7 @@ public class BeanMappingMethod extends MappingMethod { } - - private void reportErrorForUnmappedTargetPropertiesIfRequired( ) { + private void reportErrorForUnmappedTargetPropertiesIfRequired() { // fetch settings from element to implement ReportingPolicy unmappedTargetPolicy = getEffectiveUnmappedTargetPolicy(); @@ -465,13 +464,13 @@ public class BeanMappingMethod extends MappingMethod { if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.requiresReport() ) { ctx.getMessager().printMessage( - unmappedTargetPolicy.getDiagnosticKind(), - MessageFormat.format( - "Unmapped target {0,choice,1#property|1 propertyMappings, MethodReference factoryMethod, - boolean mapNullToDefault ) { + boolean mapNullToDefault) { super( method ); this.propertyMappings = propertyMappings; @@ -532,7 +531,7 @@ public class BeanMappingMethod extends MappingMethod { public List getSourceParametersExcludingPrimitives() { List sourceParameters = new ArrayList(); for ( Parameter sourceParam : getSourceParameters() ) { - if (!sourceParam.getType().isPrimitive()) { + if ( !sourceParam.getType().isPrimitive() ) { sourceParameters.add( sourceParam ); } } @@ -543,7 +542,7 @@ public class BeanMappingMethod extends MappingMethod { public List getSourcePrimitiveParameters() { List sourceParameters = new ArrayList(); for ( Parameter sourceParam : getSourceParameters() ) { - if (sourceParam.getType().isPrimitive()) { + if ( sourceParam.getType().isPrimitive() ) { sourceParameters.add( sourceParam ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java index 61cfd1743..68c5601ac 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java @@ -21,7 +21,6 @@ package org.mapstruct.ap.model; import java.util.Collections; import java.util.List; import java.util.Set; - import javax.lang.model.type.TypeMirror; import javax.tools.Diagnostic; @@ -111,22 +110,22 @@ public class IterableMappingMethod extends MappingMethod { // mapNullToDefault NullValueMappingPrism prism = NullValueMappingPrism.getInstanceOn( method.getExecutable() ); boolean mapNullToDefault - = MapperConfig.getInstanceOn( ctx.getMapperTypeElement() ).isMapToDefault( prism ); + = MapperConfig.getInstanceOn( ctx.getMapperTypeElement() ).isMapToDefault( prism ); MethodReference factoryMethod = AssignmentFactory.createFactoryMethod( method.getReturnType(), ctx ); return new IterableMappingMethod( - method, - assignment, - factoryMethod, - mapNullToDefault, - ctx.getTypeFactory() + method, + assignment, + factoryMethod, + mapNullToDefault, + ctx.getTypeFactory() ); } } private IterableMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod, - boolean mapNullToDefault, TypeFactory typeFactory ) { + boolean mapNullToDefault, TypeFactory typeFactory) { super( method ); this.elementAssignment = parameterAssignment; this.factoryMethod = factoryMethod; @@ -157,7 +156,7 @@ public class IterableMappingMethod extends MappingMethod { types.addAll( elementAssignment.getImportTypes() ); } - if (mapNullToDefault) { + if ( mapNullToDefault ) { types.add( typeFactory.getType( Collections.class ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java index ccfdfbe19..72b1b0f10 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java @@ -21,7 +21,6 @@ package org.mapstruct.ap.model; import java.util.Collections; import java.util.List; import java.util.Set; - import javax.lang.model.type.TypeMirror; import javax.tools.Diagnostic; @@ -140,10 +139,10 @@ public class MapMappingMethod extends MappingMethod { ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, message, method.getExecutable() ); } - // mapNullToDefault + // mapNullToDefault NullValueMappingPrism prism = NullValueMappingPrism.getInstanceOn( method.getExecutable() ); boolean mapNullToDefault = - MapperConfig.getInstanceOn( ctx.getMapperTypeElement() ).isMapToDefault( prism ); + MapperConfig.getInstanceOn( ctx.getMapperTypeElement() ).isMapToDefault( prism ); MethodReference factoryMethod = AssignmentFactory.createFactoryMethod( method.getReturnType(), ctx ); @@ -151,18 +150,18 @@ public class MapMappingMethod extends MappingMethod { valueAssignment = new LocalVarWrapper( valueAssignment, method.getThrownTypes() ); return new MapMappingMethod( - method, - keyAssignment, - valueAssignment, - factoryMethod, - mapNullToDefault, - ctx.getTypeFactory() + method, + keyAssignment, + valueAssignment, + factoryMethod, + mapNullToDefault, + ctx.getTypeFactory() ); } } private MapMappingMethod(Method method, Assignment keyAssignment, Assignment valueAssignment, - MethodReference factoryMethod, boolean mapNullToDefault, TypeFactory typeFactory) { + MethodReference factoryMethod, boolean mapNullToDefault, TypeFactory typeFactory) { super( method ); this.keyAssignment = keyAssignment; @@ -202,7 +201,7 @@ public class MapMappingMethod extends MappingMethod { types.addAll( valueAssignment.getImportTypes() ); } - if (mapNullToDefault) { + if ( mapNullToDefault ) { types.add( typeFactory.getType( Collections.class ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java index 7eb9c9d72..a42e6828b 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java @@ -162,7 +162,7 @@ public class PropertyMapping extends ModelElement { Diagnostic.Kind.ERROR, String.format( "Can't map %s to \"%s %s\". " - + "Consider to declare/implement a mapping method: \"%s map(%s value)\".", + + "Consider to declare/implement a mapping method: \"%s map(%s value)\".", sourceElement, targetType, targetPropertyName, @@ -182,17 +182,17 @@ public class PropertyMapping extends ModelElement { } private Assignment assignObject(Type sourceType, Type targetType, TargetAccessorType targetAccessorType, - Assignment rhs ) { + Assignment rhs) { Assignment result = rhs; if ( targetAccessorType == TargetAccessorType.SETTER ) { result = new SetterWrapper( result, method.getThrownTypes() ); if ( !sourceType.isPrimitive() - && ( result.getType() == TYPE_CONVERTED - || result.getType() == TYPE_CONVERTED_MAPPED - || result.getType() == DIRECT && targetType.isPrimitive() ) ) { - // for primitive types null check is not possible at all, but a conversion needs + && ( result.getType() == TYPE_CONVERTED + || result.getType() == TYPE_CONVERTED_MAPPED + || result.getType() == DIRECT && targetType.isPrimitive() ) ) { + // for primitive types null check is not possible at all, but a conversion needs // a null check. result = new NullCheckWrapper( result ); } @@ -201,10 +201,10 @@ public class PropertyMapping extends ModelElement { // TargetAccessorType must be ADDER if ( getSourceType().isCollectionType() ) { result = new AdderWrapper( - result, - method.getThrownTypes(), - getSourceRef(), - sourceType + result, + method.getThrownTypes(), + getSourceRef(), + sourceType ); } else { @@ -217,7 +217,7 @@ public class PropertyMapping extends ModelElement { } - private Assignment assignCollection( Type targetType, TargetAccessorType targetAccessorType, Assignment rhs ) { + private Assignment assignCollection(Type targetType, TargetAccessorType targetAccessorType, Assignment rhs) { Assignment result = rhs; @@ -237,9 +237,9 @@ public class PropertyMapping extends ModelElement { // target accessor is setter, so wrap the setter in setter map/ collection handling result = new SetterCollectionOrMapWrapper( - result, - targetAccessor.getSimpleName().toString(), - newCollectionOrMap + result, + targetAccessor.getSimpleName().toString(), + newCollectionOrMap ); } else { diff --git a/processor/src/main/java/org/mapstruct/ap/prism/PrismGenerator.java b/processor/src/main/java/org/mapstruct/ap/prism/PrismGenerator.java index f8b01fcb8..300cf8f97 100644 --- a/processor/src/main/java/org/mapstruct/ap/prism/PrismGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/prism/PrismGenerator.java @@ -22,17 +22,16 @@ import javax.xml.bind.annotation.XmlElementDecl; import net.java.dev.hickory.prism.GeneratePrism; import net.java.dev.hickory.prism.GeneratePrisms; - import org.mapstruct.DecoratedWith; import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.IterableMapping; import org.mapstruct.MapMapping; -import org.mapstruct.NullValueMapping; import org.mapstruct.Mapper; import org.mapstruct.MapperConfig; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; import org.mapstruct.Mappings; +import org.mapstruct.NullValueMapping; import org.mapstruct.Qualifier; import org.mapstruct.TargetType; @@ -52,8 +51,8 @@ import org.mapstruct.TargetType; @GeneratePrism(value = DecoratedWith.class, publicAccess = true), @GeneratePrism(value = MapperConfig.class, publicAccess = true), @GeneratePrism(value = InheritInverseConfiguration.class, publicAccess = true), - @GeneratePrism( value = Qualifier.class, publicAccess = true ), - @GeneratePrism( value = NullValueMapping.class, publicAccess = true ), + @GeneratePrism(value = Qualifier.class, publicAccess = true), + @GeneratePrism(value = NullValueMapping.class, publicAccess = true), // external types @GeneratePrism(value = XmlElementDecl.class, publicAccess = true) diff --git a/processor/src/main/java/org/mapstruct/ap/util/MapperConfig.java b/processor/src/main/java/org/mapstruct/ap/util/MapperConfig.java index 3452d4079..672a3c2eb 100644 --- a/processor/src/main/java/org/mapstruct/ap/util/MapperConfig.java +++ b/processor/src/main/java/org/mapstruct/ap/util/MapperConfig.java @@ -22,20 +22,18 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; - import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; -import org.mapstruct.ap.prism.NullValueMappingStrategyPrism; -import org.mapstruct.ap.prism.NullValueMappingPrism; - import org.mapstruct.ap.option.ReportingPolicy; import org.mapstruct.ap.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.prism.MapperConfigPrism; import org.mapstruct.ap.prism.MapperPrism; +import org.mapstruct.ap.prism.NullValueMappingPrism; +import org.mapstruct.ap.prism.NullValueMappingStrategyPrism; import static org.mapstruct.ap.prism.CollectionMappingStrategyPrism.valueOf; @@ -124,7 +122,7 @@ public class MapperConfig { // check on method level if ( mapNullToDefault != null ) { NullValueMappingStrategyPrism methodPolicy - = NullValueMappingStrategyPrism.valueOf( mapNullToDefault.value() ); + = NullValueMappingStrategyPrism.valueOf( mapNullToDefault.value() ); if ( methodPolicy != NullValueMappingStrategyPrism.DEFAULT ) { return methodPolicy == NullValueMappingStrategyPrism.RETURN_DEFAULT; } @@ -132,7 +130,7 @@ public class MapperConfig { // check on mapper level NullValueMappingStrategyPrism mapperPolicy = - NullValueMappingStrategyPrism.valueOf( mapperPrism.nullValueMappingStrategy() ); + NullValueMappingStrategyPrism.valueOf( mapperPrism.nullValueMappingStrategy() ); if ( mapperPolicy != NullValueMappingStrategyPrism.DEFAULT ) { // it is not the default mapper configuration, so return the mapper configured value @@ -143,8 +141,8 @@ public class MapperConfig { else if ( mapperConfigPrism != null ) { // try the config mapper configuration NullValueMappingStrategyPrism configPolicy = - NullValueMappingStrategyPrism.valueOf( mapperConfigPrism.nullValueMappingStrategy() ); - if ( configPolicy != NullValueMappingStrategyPrism.DEFAULT ) { + NullValueMappingStrategyPrism.valueOf( mapperConfigPrism.nullValueMappingStrategy() ); + if ( configPolicy != NullValueMappingStrategyPrism.DEFAULT ) { // its not the default configuration, so return the mapper config configured value return configPolicy == NullValueMappingStrategyPrism.RETURN_DEFAULT; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapper.java index 1d7a0dc75..ea1b78ba7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapper.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.test.mapnulltodefault; -import static org.mapstruct.NullValueMappingStrategy.RETURN_DEFAULT; - import java.util.List; import java.util.Map; import java.util.UUID; @@ -32,6 +30,8 @@ import org.mapstruct.ap.test.mapnulltodefault.source.Car; import org.mapstruct.ap.test.mapnulltodefault.target.CarDto; import org.mapstruct.factory.Mappers; +import static org.mapstruct.NullValueMappingStrategy.RETURN_DEFAULT; + @Mapper(imports = UUID.class) public interface CarMapper { diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapperSettingOnConfig.java b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapperSettingOnConfig.java index 199e52148..2eae2dd47 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapperSettingOnConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapperSettingOnConfig.java @@ -23,15 +23,15 @@ import java.util.Map; import java.util.UUID; import org.mapstruct.Mapper; -import org.mapstruct.NullValueMapping; -import org.mapstruct.NullValueMappingStrategy; import org.mapstruct.Mapping; import org.mapstruct.Mappings; +import org.mapstruct.NullValueMapping; +import org.mapstruct.NullValueMappingStrategy; import org.mapstruct.ap.test.mapnulltodefault.source.Car; import org.mapstruct.ap.test.mapnulltodefault.target.CarDto; import org.mapstruct.factory.Mappers; -@Mapper(imports = UUID.class, config = CentralConfig.class ) +@Mapper(imports = UUID.class, config = CentralConfig.class) public interface CarMapperSettingOnConfig { CarMapperSettingOnConfig INSTANCE = Mappers.getMapper( CarMapperSettingOnConfig.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapperSettingOnMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapperSettingOnMapper.java index ba35f95b8..4add75d2d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapperSettingOnMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapperSettingOnMapper.java @@ -23,15 +23,15 @@ import java.util.Map; import java.util.UUID; import org.mapstruct.Mapper; -import org.mapstruct.NullValueMapping; -import org.mapstruct.NullValueMappingStrategy; import org.mapstruct.Mapping; import org.mapstruct.Mappings; +import org.mapstruct.NullValueMapping; +import org.mapstruct.NullValueMappingStrategy; import org.mapstruct.ap.test.mapnulltodefault.source.Car; import org.mapstruct.ap.test.mapnulltodefault.target.CarDto; import org.mapstruct.factory.Mappers; -@Mapper(imports = UUID.class, nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT ) +@Mapper(imports = UUID.class, nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) public interface CarMapperSettingOnMapper { CarMapperSettingOnMapper INSTANCE = Mappers.getMapper( CarMapperSettingOnMapper.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapperTest.java index a6c1c3fa7..0263176a6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapperTest.java @@ -22,8 +22,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.fest.assertions.Assertions.assertThat; - import org.junit.Test; import org.junit.runner.RunWith; @@ -32,6 +30,8 @@ import org.mapstruct.ap.test.mapnulltodefault.target.CarDto; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.fest.assertions.Assertions.assertThat; + @WithClasses({ Car.class, CarDto.class, @@ -108,41 +108,41 @@ public class CarMapperTest { //when List carDtos1 = CarMapper.INSTANCE.carsToCarDtos( Arrays.asList( car ) ); - //then - assertThat( carDtos1 ).isNotNull(); - assertThat( carDtos1.size() ).isEqualTo( 1 ); + //then + assertThat( carDtos1 ).isNotNull(); + assertThat( carDtos1.size() ).isEqualTo( 1 ); - //when - List carDtos2 = CarMapper.INSTANCE.carsToCarDtos( null ); + //when + List carDtos2 = CarMapper.INSTANCE.carsToCarDtos( null ); - //then - assertThat( carDtos2 ).isNotNull(); - assertThat( carDtos2.isEmpty() ).isTrue(); + //then + assertThat( carDtos2 ).isNotNull(); + assertThat( carDtos2.isEmpty() ).isTrue(); } @Test - @SuppressWarnings( { "rawtypes", "unchecked" } ) + @SuppressWarnings({ "rawtypes", "unchecked" }) public void shouldMapMapWithNullArg() { //given Car car = new Car( "Morris", 2 ); Map carMap = new HashMap(); - carMap.put( 1, car); + carMap.put( 1, car ); //when Map carDtoMap1 = CarMapper.INSTANCE.carsToCarDtoMap( carMap ); - //then - assertThat( carDtoMap1 ).isNotNull(); - assertThat( carDtoMap1.size() ).isEqualTo( 1 ); + //then + assertThat( carDtoMap1 ).isNotNull(); + assertThat( carDtoMap1.size() ).isEqualTo( 1 ); - //when - Map carDtoMap2 = CarMapper.INSTANCE.carsToCarDtoMap( null ); + //when + Map carDtoMap2 = CarMapper.INSTANCE.carsToCarDtoMap( null ); - //then - assertThat( carDtoMap2 ).isNotNull(); - assertThat( carDtoMap2.isEmpty() ).isTrue(); + //then + assertThat( carDtoMap2 ).isNotNull(); + assertThat( carDtoMap2.isEmpty() ).isTrue(); } @@ -163,23 +163,23 @@ public class CarMapperTest { @Test public void shouldMapIterableWithNullArgOnMapper() { - //when - List carDtos = CarMapperSettingOnMapper.INSTANCE.carsToCarDtos( null ); + //when + List carDtos = CarMapperSettingOnMapper.INSTANCE.carsToCarDtos( null ); - //then - assertThat( carDtos ).isNotNull(); - assertThat( carDtos.isEmpty() ).isTrue(); + //then + assertThat( carDtos ).isNotNull(); + assertThat( carDtos.isEmpty() ).isTrue(); } @Test public void shouldMapMapWithNullArgOnMapper() { - //when - Map carDtoMap = CarMapperSettingOnMapper.INSTANCE.carsToCarDtoMap( null ); + //when + Map carDtoMap = CarMapperSettingOnMapper.INSTANCE.carsToCarDtoMap( null ); - //then - assertThat( carDtoMap ).isNull(); + //then + assertThat( carDtoMap ).isNull(); } @@ -201,23 +201,23 @@ public class CarMapperTest { @Test public void shouldMapIterableWithNullArgOnConfig() { - //when - List carDtos = CarMapperSettingOnConfig.INSTANCE.carsToCarDtos( null ); + //when + List carDtos = CarMapperSettingOnConfig.INSTANCE.carsToCarDtos( null ); - //then - assertThat( carDtos ).isNotNull(); - assertThat( carDtos.isEmpty() ).isTrue(); + //then + assertThat( carDtos ).isNotNull(); + assertThat( carDtos.isEmpty() ).isTrue(); } @Test public void shouldMapMapWithNullArgOnConfig() { - //when - Map carDtoMap = CarMapperSettingOnConfig.INSTANCE.carsToCarDtoMap( null ); + //when + Map carDtoMap = CarMapperSettingOnConfig.INSTANCE.carsToCarDtoMap( null ); - //then - assertThat( carDtoMap ).isNull(); + //then + assertThat( carDtoMap ).isNull(); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CentralConfig.java b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CentralConfig.java index aeb077c13..7fff295a3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CentralConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CentralConfig.java @@ -18,14 +18,13 @@ */ package org.mapstruct.ap.test.mapnulltodefault; -import org.mapstruct.NullValueMappingStrategy; import org.mapstruct.MapperConfig; +import org.mapstruct.NullValueMappingStrategy; /** - * * @author Sjaak Derksen */ -@MapperConfig( nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT ) +@MapperConfig(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) public class CentralConfig { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/target/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/target/CarDto.java index 8e4ccb9f1..09bb9fe75 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/target/CarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/target/CarDto.java @@ -54,7 +54,7 @@ public class CarDto { return model; } - public void setModel( String model ) { + public void setModel(String model) { this.model = model; } @@ -62,7 +62,7 @@ public class CarDto { return catalogId; } - public void setCatalogId( String catalogId ) { + public void setCatalogId(String catalogId) { this.catalogId = catalogId; }