From 4101ed86c9a22116b1520173359b26d0b5a56613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Ehrenm=C3=BCller?= Date: Tue, 2 Feb 2016 09:01:49 +0100 Subject: [PATCH] #729 added unittest for mapping property of collection to primitive --- .../ErroneousCollectionMappingTest.java | 15 ++++++++ ...usCollectionToPrimitivePropertyMapper.java | 28 +++++++++++++++ .../ap/test/collection/erroneous/Source.java | 34 +++++++++++++++++++ .../ap/test/collection/erroneous/Target.java | 32 +++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionToPrimitivePropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Target.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java index 5a3950da5..feb6e8f5b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java @@ -56,6 +56,21 @@ public class ErroneousCollectionMappingTest { public void shouldFailToGenerateImplementationBetweenCollectionAndNonCollection() { } + @Test + @IssueKey("729") + @WithClasses({ ErroneousCollectionToPrimitivePropertyMapper.class, Source.class, Target.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousCollectionToPrimitivePropertyMapper.class, + kind = Kind.ERROR, + line = 26, + messageRegExp = "Can't map property \"java.util.List strings\" to \"int strings\". Consider to declare/implement a mapping method: \"int map\\(java.util.List value\\)\"") + } + ) + public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { + } + @Test @IssueKey("417") @WithClasses({ EmptyItererableMappingMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionToPrimitivePropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionToPrimitivePropertyMapper.java new file mode 100644 index 000000000..f5d696c7f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionToPrimitivePropertyMapper.java @@ -0,0 +1,28 @@ +/** + * 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.collection.erroneous; + +import org.mapstruct.Mapper; + +@Mapper +public interface ErroneousCollectionToPrimitivePropertyMapper { + + Target mapCollectionToNonCollectionAsProperty(Source source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Source.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Source.java new file mode 100644 index 000000000..a389a1eff --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Source.java @@ -0,0 +1,34 @@ +/** + * 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.collection.erroneous; + +import java.util.List; + +public class Source { + + private List strings; + + public List getStrings() { + return strings; + } + + public void setStrings(List strings) { + this.strings = strings; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Target.java new file mode 100644 index 000000000..3c5aef027 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Target.java @@ -0,0 +1,32 @@ +/** + * 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.collection.erroneous; + +public class Target { + + private int strings; + + public int getStrings() { + return strings; + } + + public void setStrings(int strings) { + this.strings = strings; + } +}