|
21 | 21 | */ |
22 | 22 | public class ValueMappingCompletionTestCase extends MapstructBaseCompletionTestCase { |
23 | 23 |
|
| 24 | + @Language("JAVA") |
| 25 | + private static final String SOURCE_VALUE_MAPPING_DYNAMIC = "import org.mapstruct.Mapper;\n" + |
| 26 | + "import org.mapstruct.ValueMapping;\n" + |
| 27 | + "import org.mapstruct.example.ExternalRoofType;\n" + |
| 28 | + "import org.mapstruct.example.RoofType;\n" + |
| 29 | + "\n" + |
| 30 | + "@Mapper\n" + |
| 31 | + "public interface RoofTypeMapper {\n" + |
| 32 | + "\n" + |
| 33 | + " %s" + |
| 34 | + " ExternalRoofType map(RoofType type);\n" + |
| 35 | + "}"; |
| 36 | + |
| 37 | + @Language("JAVA") |
| 38 | + private static final String SOURCE_VALUE_MAPPINGS_DYNAMIC = "import org.mapstruct.Mapper;\n" + |
| 39 | + "import org.mapstruct.ValueMapping;\n" + |
| 40 | + "import org.mapstruct.ValueMappings;\n" + |
| 41 | + "import org.mapstruct.example.ExternalRoofType;\n" + |
| 42 | + "import org.mapstruct.example.RoofType;\n" + |
| 43 | + "\n" + |
| 44 | + "@Mapper\n" + |
| 45 | + "public interface RoofTypeMapper {\n" + |
| 46 | + "\n" + |
| 47 | + " @ValueMappings({\n%s\n})\n" + |
| 48 | + " ExternalRoofType map(RoofType type);\n" + |
| 49 | + "}"; |
| 50 | + |
24 | 51 | @Language("JAVA") |
25 | 52 | private static final String SOURCE_VALUE_MAPPING = "import org.mapstruct.Mapper;\n" + |
26 | 53 | "import org.mapstruct.ValueMapping;\n" + |
@@ -82,6 +109,100 @@ public void testSourceValueMappingVariants() { |
82 | 109 | ); |
83 | 110 | } |
84 | 111 |
|
| 112 | + public void testSourceValueMappingWithExisting() { |
| 113 | + String source = String.format( |
| 114 | + SOURCE_VALUE_MAPPING_DYNAMIC, |
| 115 | + "@ValueMapping(source = \"GAMBREL\", target = \"NORMAL\")\n" + |
| 116 | + "@ValueMapping(source = \"<caret>%s\", target = \"STANDARD\")\n" |
| 117 | + ); |
| 118 | + myFixture.configureByText( JavaFileType.INSTANCE, source ); |
| 119 | + complete(); |
| 120 | + |
| 121 | + assertThat( myItems ) |
| 122 | + .extracting( LookupElement::getLookupString ) |
| 123 | + .containsExactlyInAnyOrder( |
| 124 | + "OPEN", |
| 125 | + "BOX", |
| 126 | + "NORMAL" |
| 127 | + ); |
| 128 | + assertThat( myItems ) |
| 129 | + .extracting( LookupElementPresentation::renderElement ) |
| 130 | + .usingElementComparatorIgnoringFields( "myIcon" ) |
| 131 | + .containsExactlyInAnyOrder( |
| 132 | + createField( "OPEN", "RoofType" ), |
| 133 | + createField( "BOX", "RoofType" ), |
| 134 | + createField( "NORMAL", "RoofType" ) |
| 135 | + ); |
| 136 | + } |
| 137 | + |
| 138 | + public void testSourceValueMappingsWithExisting() { |
| 139 | + String source = String.format( |
| 140 | + SOURCE_VALUE_MAPPINGS_DYNAMIC, |
| 141 | + "@ValueMapping(source = \"GAMBREL\", target = \"NORMAL\"),\n" + |
| 142 | + "@ValueMapping(source = \"<caret>%s\", target = \"STANDARD\")\n" |
| 143 | + ); |
| 144 | + myFixture.configureByText( JavaFileType.INSTANCE, source ); |
| 145 | + complete(); |
| 146 | + |
| 147 | + assertThat( myItems ) |
| 148 | + .extracting( LookupElement::getLookupString ) |
| 149 | + .containsExactlyInAnyOrder( |
| 150 | + "OPEN", |
| 151 | + "BOX", |
| 152 | + "NORMAL" |
| 153 | + ); |
| 154 | + assertThat( myItems ) |
| 155 | + .extracting( LookupElementPresentation::renderElement ) |
| 156 | + .usingElementComparatorIgnoringFields( "myIcon" ) |
| 157 | + .containsExactlyInAnyOrder( |
| 158 | + createField( "OPEN", "RoofType" ), |
| 159 | + createField( "BOX", "RoofType" ), |
| 160 | + createField( "NORMAL", "RoofType" ) |
| 161 | + ); |
| 162 | + } |
| 163 | + |
| 164 | + public void testSourceValueMappingAllValuesAlreadyMapped() { |
| 165 | + String source = String.format( |
| 166 | + SOURCE_VALUE_MAPPING_DYNAMIC, |
| 167 | + "@ValueMapping(source = \"OPEN\", target = \"NORMAL\")\n" + |
| 168 | + "@ValueMapping(source = \"BOX\", target = \"NORMAL\")\n" + |
| 169 | + "@ValueMapping(source = \"GAMBREL\", target = \"NORMAL\")\n" + |
| 170 | + "@ValueMapping(source = \"NORMAL\", target = \"NORMAL\")\n" + |
| 171 | + "@ValueMapping(source = \"<caret>%s\", target = \"STANDARD\")\n" |
| 172 | + ); |
| 173 | + myFixture.configureByText( JavaFileType.INSTANCE, source ); |
| 174 | + complete(); |
| 175 | + |
| 176 | + assertThat( myItems ) |
| 177 | + .extracting( LookupElement::getLookupString ) |
| 178 | + .isEmpty(); |
| 179 | + assertThat( myItems ) |
| 180 | + .extracting( LookupElementPresentation::renderElement ) |
| 181 | + .usingElementComparatorIgnoringFields( "myIcon" ) |
| 182 | + .isEmpty(); |
| 183 | + } |
| 184 | + |
| 185 | + public void testSourceValueMappingsAllValuesAlreadyMapped() { |
| 186 | + String source = String.format( |
| 187 | + SOURCE_VALUE_MAPPINGS_DYNAMIC, |
| 188 | + "@ValueMapping(source = \"OPEN\", target = \"NORMAL\"),\n" + |
| 189 | + "@ValueMapping(source = \"BOX\", target = \"NORMAL\"),\n" + |
| 190 | + "@ValueMapping(source = \"GAMBREL\", target = \"NORMAL\"),\n" + |
| 191 | + "@ValueMapping(source = \"NORMAL\", target = \"NORMAL\"),\n" + |
| 192 | + "@ValueMapping(source = \"<caret>%s\", target = \"STANDARD\")\n" |
| 193 | + ); |
| 194 | + myFixture.configureByText( JavaFileType.INSTANCE, source ); |
| 195 | + complete(); |
| 196 | + |
| 197 | + assertThat( myItems ) |
| 198 | + .extracting( LookupElement::getLookupString ) |
| 199 | + .isEmpty(); |
| 200 | + assertThat( myItems ) |
| 201 | + .extracting( LookupElementPresentation::renderElement ) |
| 202 | + .usingElementComparatorIgnoringFields( "myIcon" ) |
| 203 | + .isEmpty(); |
| 204 | + } |
| 205 | + |
85 | 206 | public void testSourceValueMappingResolveToEnum() { |
86 | 207 | myFixture.configureByText( JavaFileType.INSTANCE, String.format( SOURCE_VALUE_MAPPING, "NORMAL" ) ); |
87 | 208 |
|
|
0 commit comments