mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#295 Adding test for bean mapping method with several source parameters
This commit is contained in:
parent
9f7a00c556
commit
48c20d4dd0
@ -27,7 +27,9 @@ import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.NullValueMapping;
|
||||
import org.mapstruct.ap.test.nullvaluemapping.source.Car;
|
||||
import org.mapstruct.ap.test.nullvaluemapping.source.Driver;
|
||||
import org.mapstruct.ap.test.nullvaluemapping.target.CarDto;
|
||||
import org.mapstruct.ap.test.nullvaluemapping.target.DriverAndCarDto;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import static org.mapstruct.NullValueMappingStrategy.RETURN_DEFAULT;
|
||||
@ -59,4 +61,9 @@ public interface CarMapper {
|
||||
|
||||
@NullValueMapping(RETURN_DEFAULT)
|
||||
Map<Integer, CarDto> carsToCarDtoMap(Map<Integer, Car> cars);
|
||||
|
||||
@NullValueMapping(RETURN_DEFAULT)
|
||||
DriverAndCarDto driverAndCarToDto(Driver driver, Car car);
|
||||
|
||||
DriverAndCarDto driverAndCarToDtoReturningNull(Driver driver, Car car);
|
||||
}
|
||||
|
@ -26,7 +26,9 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mapstruct.ap.test.nullvaluemapping.source.Car;
|
||||
import org.mapstruct.ap.test.nullvaluemapping.source.Driver;
|
||||
import org.mapstruct.ap.test.nullvaluemapping.target.CarDto;
|
||||
import org.mapstruct.ap.test.nullvaluemapping.target.DriverAndCarDto;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||
|
||||
@ -34,7 +36,9 @@ import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
@WithClasses({
|
||||
Car.class,
|
||||
Driver.class,
|
||||
CarDto.class,
|
||||
DriverAndCarDto.class,
|
||||
CarMapper.class,
|
||||
CarMapperSettingOnMapper.class,
|
||||
CentralConfig.class,
|
||||
@ -118,7 +122,6 @@ public class CarMapperTest {
|
||||
//then
|
||||
assertThat( carDtos2 ).isNotNull();
|
||||
assertThat( carDtos2.isEmpty() ).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -143,7 +146,6 @@ public class CarMapperTest {
|
||||
//then
|
||||
assertThat( carDtoMap2 ).isNotNull();
|
||||
assertThat( carDtoMap2.isEmpty() ).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -169,7 +171,6 @@ public class CarMapperTest {
|
||||
//then
|
||||
assertThat( carDtos ).isNotNull();
|
||||
assertThat( carDtos.isEmpty() ).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -180,7 +181,6 @@ public class CarMapperTest {
|
||||
|
||||
//then
|
||||
assertThat( carDtoMap ).isNull();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -197,7 +197,6 @@ public class CarMapperTest {
|
||||
assertThat( carDto.getCatalogId() ).isNotEmpty();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldMapIterableWithNullArgOnConfig() {
|
||||
|
||||
@ -207,7 +206,6 @@ public class CarMapperTest {
|
||||
//then
|
||||
assertThat( carDtos ).isNotNull();
|
||||
assertThat( carDtos.isEmpty() ).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -218,6 +216,22 @@ public class CarMapperTest {
|
||||
|
||||
//then
|
||||
assertThat( carDtoMap ).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldApplyConfiguredStrategyForMethodWithSeveralSourceParams() {
|
||||
//when
|
||||
DriverAndCarDto result = CarMapper.INSTANCE.driverAndCarToDto( null, null );
|
||||
|
||||
//then
|
||||
assertThat( result ).isNotNull();
|
||||
assertThat( result.getMake() ).isNull();
|
||||
assertThat( result.getName() ).isNull();
|
||||
|
||||
//when
|
||||
result = CarMapper.INSTANCE.driverAndCarToDtoReturningNull( null, null );
|
||||
|
||||
//then
|
||||
assertThat( result ).isNull();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 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.nullvaluemapping.source;
|
||||
|
||||
public class Driver {
|
||||
|
||||
private String name;
|
||||
|
||||
public Driver(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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.nullvaluemapping.target;
|
||||
|
||||
public class DriverAndCarDto {
|
||||
|
||||
private String name;
|
||||
private String make;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getMake() {
|
||||
return make;
|
||||
}
|
||||
|
||||
public void setMake(String make) {
|
||||
this.make = make;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user