#855 Show incorrect ordering of properties

This commit is contained in:
Markus Heberling 2016-08-18 11:29:01 +02:00 committed by Andreas Gudian
parent 75021ada1b
commit 5d0bc08e2e
4 changed files with 138 additions and 3 deletions

View File

@ -39,4 +39,10 @@ public interface AddressMapper {
@Mapping(target = "lastName", dependsOn = { "firstName", "middleName" })
})
PersonDto personToDto(Person person);
@Mappings({
@Mapping(target = "field0", dependsOn = "field2"),
@Mapping(target = "order", ignore = true)
})
DemoDTO demoToDemoDto(Demo demo);
}

View File

@ -0,0 +1,67 @@
/**
* 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.dependency;
public class Demo {
private String field0;
private String field1;
private String field2;
private String field3;
private String field4;
public String getField0() {
return field0;
}
public void setField0(String field0) {
this.field0 = field0;
}
public String getField1() {
return field1;
}
public void setField1(String field1) {
this.field1 = field1;
}
public String getField2() {
return field2;
}
public void setField2(String field2) {
this.field2 = field2;
}
public String getField3() {
return field3;
}
public void setField3(String field3) {
this.field3 = field3;
}
public String getField4() {
return field4;
}
public void setField4(String field4) {
this.field4 = field4;
}
}

View File

@ -0,0 +1,52 @@
/**
* 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.dependency;
import java.util.LinkedList;
import java.util.List;
public class DemoDTO {
private List<String> order = new LinkedList<String>();
public void setField0(String field0) {
order.add( "field0" );
}
public void setField1(String field1) {
order.add( "field1" );
}
public void setField2(String field2) {
order.add( "field2" );
}
public void setField3(String field3) {
order.add( "field3" );
}
public void setField4(String field4) {
order.add( "field4" );
}
public List<String> getOrder() {
return order;
}
}

View File

@ -18,8 +18,6 @@
*/
package org.mapstruct.ap.test.dependency;
import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.Mapping;
@ -30,15 +28,27 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/**
* Test for ordering mapped attributes by means of {@link Mapping#dependsOn()}.
*
* @author Gunnar Morling
*/
@WithClasses({ Person.class, PersonDto.class, Address.class, AddressDto.class, AddressMapper.class })
@WithClasses({ Person.class, PersonDto.class, Address.class, AddressDto.class, AddressMapper.class,
Demo.class, DemoDTO.class })
@RunWith(AnnotationProcessorTestRunner.class)
public class OrderingTest {
@Test
public void shouldApplyCorrectOrdering() {
Demo source = new Demo();
DemoDTO target = AddressMapper.INSTANCE.demoToDemoDto( source );
assertThat( target.getOrder() ).containsExactly( "field1", "field2", "field0", "field3", "field4" );
}
@Test
@IssueKey("304")
public void shouldApplyChainOfDependencies() {