From fc0a4570b7c603aa4b5d653cbbc0fe0fb2d8e652 Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Sun, 12 Jan 2014 21:07:11 +0100 Subject: [PATCH] #89 create test for correct instanciation of referenced mappers with default component model --- .../org/mapstruct/ap/test/references/Bar.java | 35 ++++++++++++ .../org/mapstruct/ap/test/references/Foo.java | 35 ++++++++++++ .../ap/test/references/FooMapper.java | 30 ++++++++++ .../references/ReferencedCustomMapper.java | 29 ++++++++++ .../test/references/ReferencedMapperTest.java | 56 +++++++++++++++++++ .../mapstruct/ap/test/references/Source.java | 44 +++++++++++++++ .../test/references/SourceTargetMapper.java | 33 +++++++++++ .../mapstruct/ap/test/references/Target.java | 44 +++++++++++++++ 8 files changed, 306 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/references/Bar.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/references/Foo.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/references/FooMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/references/ReferencedCustomMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/references/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/references/SourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/references/Target.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/Bar.java b/processor/src/test/java/org/mapstruct/ap/test/references/Bar.java new file mode 100644 index 000000000..c2f1b4e9c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/references/Bar.java @@ -0,0 +1,35 @@ +/** + * 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.references; + +/** + * @author Andreas Gudian + * + */ +public class Bar { + private String prop1; + + public String getProp1() { + return prop1; + } + + public void setProp1(String prop1) { + this.prop1 = prop1; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/references/Foo.java new file mode 100644 index 000000000..fd596669b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/references/Foo.java @@ -0,0 +1,35 @@ +/** + * 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.references; + +/** + * @author Andreas Gudian + * + */ +public class Foo { + private String prop1; + + public String getProp1() { + return prop1; + } + + public void setProp1(String prop1) { + this.prop1 = prop1; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/FooMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/FooMapper.java new file mode 100644 index 000000000..269d0e1ed --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/references/FooMapper.java @@ -0,0 +1,30 @@ +/** + * 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.references; + +import org.mapstruct.Mapper; + +/** + * @author Andreas Gudian + * + */ +@Mapper +public interface FooMapper { + Bar fooToBar(Foo source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedCustomMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedCustomMapper.java new file mode 100644 index 000000000..57ff5620b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedCustomMapper.java @@ -0,0 +1,29 @@ +/** + * 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.references; + +/** + * @author Andreas Gudian + * + */ +public class ReferencedCustomMapper { + public long incrementingIntToLong(int source) { + return source + 1; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java new file mode 100644 index 000000000..9233a492c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java @@ -0,0 +1,56 @@ +/** + * 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.references; + +import static org.fest.assertions.Assertions.assertThat; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.MapperTestBase; +import org.mapstruct.ap.testutil.WithClasses; +import org.testng.annotations.Test; + +/** + * @author Andreas Gudian + * + */ +@IssueKey( "82" ) +@WithClasses( { Bar.class, Foo.class, FooMapper.class, ReferencedCustomMapper.class, Source.class, + SourceTargetMapper.class, Target.class } ) +public class ReferencedMapperTest extends MapperTestBase { + @Test + public void referencedMappersAreInstatiatedCorrectly() { + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( createSource() ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp1() ).isEqualTo( 43 ); + assertThat( target.getProp2() ).isNotNull(); + assertThat( target.getProp2().getProp1() ).isEqualTo( "foo" ); + } + + private Source createSource() { + Source source = new Source(); + source.setProp1( 42 ); + + Foo prop2 = new Foo(); + prop2.setProp1( "foo" ); + source.setProp2( prop2 ); + + return source; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/Source.java b/processor/src/test/java/org/mapstruct/ap/test/references/Source.java new file mode 100644 index 000000000..9051df79e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/references/Source.java @@ -0,0 +1,44 @@ +/** + * 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.references; + +/** + * @author Andreas Gudian + * + */ +public class Source { + private int prop1; + private Foo prop2; + + public int getProp1() { + return prop1; + } + + public void setProp1(int prop1) { + this.prop1 = prop1; + } + + public Foo getProp2() { + return prop2; + } + + public void setProp2(Foo prop2) { + this.prop2 = prop2; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/SourceTargetMapper.java new file mode 100644 index 000000000..ee66db22a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/references/SourceTargetMapper.java @@ -0,0 +1,33 @@ +/** + * 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.references; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Andreas Gudian + * + */ +@Mapper( uses = { FooMapper.class, ReferencedCustomMapper.class } ) +public interface SourceTargetMapper { + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + Target sourceToTarget(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/Target.java b/processor/src/test/java/org/mapstruct/ap/test/references/Target.java new file mode 100644 index 000000000..0aa12b397 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/references/Target.java @@ -0,0 +1,44 @@ +/** + * 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.references; + +/** + * @author Andreas Gudian + * + */ +public class Target { + private long prop1; + private Bar prop2; + + public long getProp1() { + return prop1; + } + + public void setProp1(long prop1) { + this.prop1 = prop1; + } + + public Bar getProp2() { + return prop2; + } + + public void setProp2(Bar prop2) { + this.prop2 = prop2; + } +}