|
| 1 | +/* |
| 2 | + * Copyright MapStruct Authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 |
| 5 | + */ |
| 6 | +package org.mapstruct.intellij.completion; |
| 7 | + |
| 8 | +import com.intellij.codeInsight.lookup.LookupElement; |
| 9 | +import com.intellij.codeInsight.lookup.LookupElementPresentation; |
| 10 | +import com.intellij.psi.PsiElement; |
| 11 | +import com.intellij.psi.PsiMethod; |
| 12 | +import org.mapstruct.intellij.MapstructBaseCompletionTestCase; |
| 13 | + |
| 14 | +import static org.assertj.core.api.Assertions.assertThat; |
| 15 | +import static org.mapstruct.intellij.testutil.TestUtils.createVariable; |
| 16 | + |
| 17 | +/** |
| 18 | + * @author Filip Hrisafov |
| 19 | + */ |
| 20 | +public class BeanMappingIgnoreUnmappedSourcePropertiesCompletionTestCase extends MapstructBaseCompletionTestCase { |
| 21 | + |
| 22 | + @Override |
| 23 | + protected String getTestDataPath() { |
| 24 | + return "testData/completion/beanmapping"; |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + protected void setUp() throws Exception { |
| 29 | + super.setUp(); |
| 30 | + |
| 31 | + addDirectoryToProject( "../../mapping/dto" ); |
| 32 | + } |
| 33 | + |
| 34 | + private void assertCarAutoComplete() { |
| 35 | + assertThat( myItems ) |
| 36 | + .extracting( LookupElement::getLookupString ) |
| 37 | + .containsExactlyInAnyOrder( |
| 38 | + "make", |
| 39 | + "numberOfSeats", |
| 40 | + "manufacturingDate", |
| 41 | + "driver", |
| 42 | + "passengers", |
| 43 | + "price", |
| 44 | + "category", |
| 45 | + "free" |
| 46 | + ); |
| 47 | + |
| 48 | + assertThat( myItems ) |
| 49 | + .extracting( LookupElementPresentation::renderElement ) |
| 50 | + .usingRecursiveFieldByFieldElementComparator() |
| 51 | + .containsExactlyInAnyOrder( |
| 52 | + createVariable( "make", "String" ), |
| 53 | + createVariable( "numberOfSeats", "int" ), |
| 54 | + createVariable( "manufacturingDate", "Date" ), |
| 55 | + createVariable( "driver", "Person" ), |
| 56 | + createVariable( "passengers", "List<Person>" ), |
| 57 | + createVariable( "price", "int" ), |
| 58 | + createVariable( "category", "Category" ), |
| 59 | + createVariable( "free", "boolean" ) |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + public void testBeanMappingIgnoreSourcePropertiesSingleCarMapper() { |
| 64 | + configureByTestName(); |
| 65 | + assertCarAutoComplete(); |
| 66 | + } |
| 67 | + |
| 68 | + public void testCarMapperReferenceSourcePropertyInMulti() { |
| 69 | + myFixture.configureByFile( "BeanMappingIgnoreSourcePropertiesSingleReferenceCarMapper.java" ); |
| 70 | + PsiElement reference = myFixture.getElementAtCaret(); |
| 71 | + |
| 72 | + assertThat( reference ) |
| 73 | + .isInstanceOfSatisfying( PsiMethod.class, method -> { |
| 74 | + assertThat( method.getName() ).isEqualTo( "getNumberOfSeats" ); |
| 75 | + assertThat( method.getPresentation() ).isNotNull(); |
| 76 | + assertThat( method.getPresentation().getPresentableText() ).isEqualTo( "getNumberOfSeats()" ); |
| 77 | + assertThat( method.getParameterList().getParametersCount() ).isEqualTo( 0 ); |
| 78 | + assertThat( method.getReturnType() ).isNotNull(); |
| 79 | + assertThat( method.getReturnType().getPresentableText() ).isEqualTo( "int" ); |
| 80 | + } ); |
| 81 | + } |
| 82 | + |
| 83 | + public void testBeanMappingIgnoreSourcePropertiesMultiCarMapper() { |
| 84 | + configureByTestName(); |
| 85 | + assertCarAutoComplete(); |
| 86 | + } |
| 87 | + |
| 88 | + public void testCarMapperReferenceSourcePropertyInSingle() { |
| 89 | + myFixture.configureByFile( "BeanMappingIgnoreSourcePropertiesMultiReferenceCarMapper.java" ); |
| 90 | + PsiElement reference = myFixture.getElementAtCaret(); |
| 91 | + |
| 92 | + assertThat( reference ) |
| 93 | + .isInstanceOfSatisfying( PsiMethod.class, method -> { |
| 94 | + assertThat( method.getName() ).isEqualTo( "getNumberOfSeats" ); |
| 95 | + assertThat( method.getPresentation() ).isNotNull(); |
| 96 | + assertThat( method.getPresentation().getPresentableText() ).isEqualTo( "getNumberOfSeats()" ); |
| 97 | + assertThat( method.getParameterList().getParametersCount() ).isEqualTo( 0 ); |
| 98 | + assertThat( method.getReturnType() ).isNotNull(); |
| 99 | + assertThat( method.getReturnType().getPresentableText() ).isEqualTo( "int" ); |
| 100 | + } ); |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments