From 069a4c20673467f074a6bea61faf07251ccac82e Mon Sep 17 00:00:00 2001 From: blindpirate Date: Tue, 13 Sep 2016 04:24:24 +0800 Subject: [PATCH] fields can be used directly in inner builder (#30) inner builder can assign value to class field directly --- .gitignore | 5 +- .../handler/DisplayChoosersRunnable.java | 7 +- .../factory/CreateBuilderDialogFactory.java | 1 + .../factory/PsiFieldsForBuilderFactory.java | 4 +- .../builder/psi/BuilderPsiClassBuilder.java | 55 ++++++++++-- .../plugins/builder/psi/PsiFieldSelector.java | 6 +- .../builder/psi/PsiFieldsModifier.java | 6 ++ .../psi/model/PsiFieldsForBuilder.java | 8 +- .../handler/DisplayChoosersRunnableTest.java | 2 +- .../psi/BuilderPsiClassBuilderTest.java | 89 +++++++++++++++++++ .../builder/psi/PsiFieldSelectorTest.java | 19 +++- .../psi/model/PsiFieldsForBuilderTest.java | 9 +- 12 files changed, 187 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 9f02276..f15a1e5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,7 @@ *.ipr *.iws .idea -.idea/* \ No newline at end of file +.idea/* +.gradle/* +build/* +out/* \ No newline at end of file diff --git a/src/main/java/pl/mjedynak/idea/plugins/builder/action/handler/DisplayChoosersRunnable.java b/src/main/java/pl/mjedynak/idea/plugins/builder/action/handler/DisplayChoosersRunnable.java index d54f5b6..fa33a33 100644 --- a/src/main/java/pl/mjedynak/idea/plugins/builder/action/handler/DisplayChoosersRunnable.java +++ b/src/main/java/pl/mjedynak/idea/plugins/builder/action/handler/DisplayChoosersRunnable.java @@ -49,7 +49,8 @@ public void run() { PsiDirectory targetDirectory = createBuilderDialog.getTargetDirectory(); String className = createBuilderDialog.getClassName(); String methodPrefix = createBuilderDialog.getMethodPrefix(); - List fieldsToDisplay = getFieldsToIncludeInBuilder(psiClassFromEditor); + boolean innerBuilder = createBuilderDialog.isInnerBuilder(); + List fieldsToDisplay = getFieldsToIncludeInBuilder(psiClassFromEditor, innerBuilder); MemberChooser memberChooserDialog = memberChooserDialogFactory.getMemberChooserDialog(fieldsToDisplay, project); memberChooserDialog.show(); writeBuilderIfNecessary(targetDirectory, className, methodPrefix, memberChooserDialog, createBuilderDialog); @@ -75,8 +76,8 @@ private CreateBuilderDialog showDialog() { return dialog; } - private List getFieldsToIncludeInBuilder(PsiClass clazz) { - return psiFieldSelector.selectFieldsToIncludeInBuilder(clazz); + private List getFieldsToIncludeInBuilder(PsiClass clazz, boolean innerBuilder) { + return psiFieldSelector.selectFieldsToIncludeInBuilder(clazz, innerBuilder); } public void setPsiClassFromEditor(PsiClass psiClassFromEditor) { diff --git a/src/main/java/pl/mjedynak/idea/plugins/builder/factory/CreateBuilderDialogFactory.java b/src/main/java/pl/mjedynak/idea/plugins/builder/factory/CreateBuilderDialogFactory.java index 20d92c7..4cc7eb9 100644 --- a/src/main/java/pl/mjedynak/idea/plugins/builder/factory/CreateBuilderDialogFactory.java +++ b/src/main/java/pl/mjedynak/idea/plugins/builder/factory/CreateBuilderDialogFactory.java @@ -11,6 +11,7 @@ public class CreateBuilderDialogFactory { static final String BUILDER_SUFFIX = "Builder"; static final String METHOD_PREFIX = "with"; + private static final String DIALOG_NAME = "CreateBuilder"; private PsiHelper psiHelper; private ReferenceEditorComboWithBrowseButtonFactory referenceEditorComboWithBrowseButtonFactory; diff --git a/src/main/java/pl/mjedynak/idea/plugins/builder/factory/PsiFieldsForBuilderFactory.java b/src/main/java/pl/mjedynak/idea/plugins/builder/factory/PsiFieldsForBuilderFactory.java index 7edcd27..e1ddc38 100644 --- a/src/main/java/pl/mjedynak/idea/plugins/builder/factory/PsiFieldsForBuilderFactory.java +++ b/src/main/java/pl/mjedynak/idea/plugins/builder/factory/PsiFieldsForBuilderFactory.java @@ -21,9 +21,11 @@ public PsiFieldsForBuilderFactory(PsiFieldVerifier psiFieldVerifier) { public PsiFieldsForBuilder createPsiFieldsForBuilder(List psiElementClassMembers, PsiClass psiClass) { List psiFieldsForSetters = new ArrayList(); List psiFieldsForConstructor = new ArrayList(); + List allSelectedPsiFields = new ArrayList(); for (PsiElementClassMember psiElementClassMember : psiElementClassMembers) { PsiElement psiElement = psiElementClassMember.getPsiElement(); if (psiElement instanceof PsiField) { + allSelectedPsiFields.add((PsiField) psiElement); if (psiFieldVerifier.isSetInSetterMethod((PsiField) psiElement, psiClass)) { psiFieldsForSetters.add((PsiField) psiElement); } else if (psiFieldVerifier.isSetInConstructor((PsiField) psiElement, psiClass)) { @@ -31,6 +33,6 @@ public PsiFieldsForBuilder createPsiFieldsForBuilder(List } } } - return new PsiFieldsForBuilder(psiFieldsForSetters, psiFieldsForConstructor); + return new PsiFieldsForBuilder(psiFieldsForSetters, psiFieldsForConstructor, allSelectedPsiFields); } } diff --git a/src/main/java/pl/mjedynak/idea/plugins/builder/psi/BuilderPsiClassBuilder.java b/src/main/java/pl/mjedynak/idea/plugins/builder/psi/BuilderPsiClassBuilder.java index 7d35279..ebc78e9 100644 --- a/src/main/java/pl/mjedynak/idea/plugins/builder/psi/BuilderPsiClassBuilder.java +++ b/src/main/java/pl/mjedynak/idea/plugins/builder/psi/BuilderPsiClassBuilder.java @@ -11,8 +11,11 @@ import pl.mjedynak.idea.plugins.builder.settings.CodeStyleSettings; import pl.mjedynak.idea.plugins.builder.writer.BuilderContext; +import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Set; import static com.intellij.openapi.util.text.StringUtil.isVowel; @@ -37,6 +40,7 @@ public class BuilderPsiClassBuilder { private List psiFieldsForSetters = null; private List psiFieldsForConstructor = null; + private List allSelectedPsiFields = null; private PsiClass builderClass = null; private PsiElementFactory elementFactory = null; @@ -70,12 +74,17 @@ private void initializeFields(BuilderContext context) { srcClassFieldName = StringUtils.uncapitalize(srcClassName); psiFieldsForSetters = context.getPsiFieldsForBuilder().getFieldsForSetters(); psiFieldsForConstructor = context.getPsiFieldsForBuilder().getFieldsForConstructor(); + allSelectedPsiFields = context.getPsiFieldsForBuilder().getAllSelectedFields(); methodCreator = new MethodCreator(elementFactory, builderClassName); butMethodCreator = new ButMethodCreator(elementFactory); } public BuilderPsiClassBuilder withFields() { - psiFieldsModifier.modifyFields(psiFieldsForSetters, psiFieldsForConstructor, builderClass); + if (isInnerBuilder(builderClass)) { + psiFieldsModifier.modifyFieldsForInnerClass(allSelectedPsiFields, builderClass); + } else { + psiFieldsModifier.modifyFields(psiFieldsForSetters, psiFieldsForConstructor, builderClass); + } return this; } @@ -95,15 +104,25 @@ public BuilderPsiClassBuilder withInitializingMethod() { } public BuilderPsiClassBuilder withSetMethods(String methodPrefix) { - for (PsiField psiFieldForSetter : psiFieldsForSetters) { - createAndAddMethod(psiFieldForSetter, methodPrefix); - } - for (PsiField psiFieldForConstructor : psiFieldsForConstructor) { - createAndAddMethod(psiFieldForConstructor, methodPrefix); + if (isInnerBuilder(builderClass)) { + for (PsiField psiFieldForAssignment : allSelectedPsiFields) { + createAndAddMethod(psiFieldForAssignment, methodPrefix); + } + } else { + for (PsiField psiFieldForSetter : psiFieldsForSetters) { + createAndAddMethod(psiFieldForSetter, methodPrefix); + } + for (PsiField psiFieldForConstructor : psiFieldsForConstructor) { + createAndAddMethod(psiFieldForConstructor, methodPrefix); + } } return this; } + private boolean isInnerBuilder(PsiClass aClass) { + return aClass.hasModifierProperty("static"); + } + public BuilderPsiClassBuilder withButMethod() { PsiMethod method = butMethodCreator.butMethod(builderClassName, builderClass, srcClass); builderClass.add(method); @@ -117,7 +136,7 @@ private void createAndAddMethod(PsiField psiField, String methodPrefix) { public PsiClass build() { StringBuilder buildMethodText = new StringBuilder(); appendConstructor(buildMethodText); - appendSetMethods(buildMethodText); + appendSetMethodsOrAssignments(buildMethodText); buildMethodText.append("return ").append(srcClassFieldName).append(";}"); PsiMethod buildMethod = elementFactory.createMethodFromText(buildMethodText.toString(), srcClass); builderClass.add(buildMethod); @@ -130,8 +149,18 @@ private void appendConstructor(StringBuilder buildMethodText) { .append(srcClassFieldName).append(" = new ").append(srcClassName).append("(").append(constructorParameters).append(");"); } - private void appendSetMethods(StringBuilder buildMethodText) { - for (PsiField psiFieldsForSetter : psiFieldsForSetters) { + private void appendSetMethodsOrAssignments(StringBuilder buildMethodText) { + appendSetMethods(buildMethodText, psiFieldsForSetters); + if (isInnerBuilder(builderClass)) { + Set fieldsSetViaAssignment = new HashSet(allSelectedPsiFields); + fieldsSetViaAssignment.removeAll(psiFieldsForSetters); + fieldsSetViaAssignment.removeAll(psiFieldsForConstructor); + appendAssignments(buildMethodText, fieldsSetViaAssignment); + } + } + + private void appendSetMethods(StringBuilder buildMethodText, Collection fieldsBeSetViaSetter) { + for (PsiField psiFieldsForSetter : fieldsBeSetViaSetter) { String fieldNamePrefix = codeStyleSettings.getFieldNamePrefix(); String fieldName = psiFieldsForSetter.getName(); String fieldNameWithoutPrefix = fieldName.replaceFirst(fieldNamePrefix, ""); @@ -140,6 +169,14 @@ private void appendSetMethods(StringBuilder buildMethodText) { } } + private void appendAssignments(StringBuilder buildMethodText, Collection fieldsSetViaAssignment) { + for (PsiField field : fieldsSetViaAssignment) { + buildMethodText.append(srcClassFieldName).append(".") + .append(field.getName()).append("=").append("this.") + .append(field.getName()).append(";"); + } + } + private String createConstructorParameters() { StringBuilder sb = new StringBuilder(); for (PsiField psiField : psiFieldsForConstructor) { diff --git a/src/main/java/pl/mjedynak/idea/plugins/builder/psi/PsiFieldSelector.java b/src/main/java/pl/mjedynak/idea/plugins/builder/psi/PsiFieldSelector.java index 4efd766..913bfc4 100644 --- a/src/main/java/pl/mjedynak/idea/plugins/builder/psi/PsiFieldSelector.java +++ b/src/main/java/pl/mjedynak/idea/plugins/builder/psi/PsiFieldSelector.java @@ -23,13 +23,14 @@ public PsiFieldSelector(PsiElementClassMemberFactory psiElementClassMemberFactor this.psiFieldVerifier = psiFieldVerifier; } - public List selectFieldsToIncludeInBuilder(final PsiClass psiClass) { + public List selectFieldsToIncludeInBuilder(final PsiClass psiClass, final boolean innerBuilder) { List result = new ArrayList(); + List psiFields = Arrays.asList(psiClass.getAllFields()); Iterable filtered = filter(psiFields, new Predicate() { @Override public boolean apply(PsiField psiField) { - return isAppropriate(psiClass, psiField); + return innerBuilder || isAppropriate(psiClass, psiField); } }); @@ -41,7 +42,6 @@ public boolean apply(PsiField psiField) { private boolean isAppropriate(PsiClass psiClass, PsiField psiField) { return psiFieldVerifier.isSetInSetterMethod(psiField, psiClass) || psiFieldVerifier.isSetInConstructor(psiField, psiClass); - } diff --git a/src/main/java/pl/mjedynak/idea/plugins/builder/psi/PsiFieldsModifier.java b/src/main/java/pl/mjedynak/idea/plugins/builder/psi/PsiFieldsModifier.java index 75f7959..aa64f03 100644 --- a/src/main/java/pl/mjedynak/idea/plugins/builder/psi/PsiFieldsModifier.java +++ b/src/main/java/pl/mjedynak/idea/plugins/builder/psi/PsiFieldsModifier.java @@ -22,6 +22,12 @@ public void modifyFields(List psiFieldsForSetters, List psiF } } + public void modifyFieldsForInnerClass(List allFileds, PsiClass innerBuilderClass) { + for (PsiField field : allFileds) { + removeModifiers(field, innerBuilderClass); + } + } + private void removeModifiers(PsiField psiField, PsiClass builderClass) { PsiElement copy = psiField.copy(); removeAnnotationsFromElement(copy); diff --git a/src/main/java/pl/mjedynak/idea/plugins/builder/psi/model/PsiFieldsForBuilder.java b/src/main/java/pl/mjedynak/idea/plugins/builder/psi/model/PsiFieldsForBuilder.java index 710dc4e..bf6531e 100644 --- a/src/main/java/pl/mjedynak/idea/plugins/builder/psi/model/PsiFieldsForBuilder.java +++ b/src/main/java/pl/mjedynak/idea/plugins/builder/psi/model/PsiFieldsForBuilder.java @@ -9,10 +9,12 @@ public class PsiFieldsForBuilder { private List psiFieldsForSetters; private List psiFieldsForConstructor; + private List allSelectedPsiFields; - public PsiFieldsForBuilder(List psiFieldsForSetters, List psiFieldsForConstructor) { + public PsiFieldsForBuilder(List psiFieldsForSetters, List psiFieldsForConstructor, List allSelectedPsiFields) { this.psiFieldsForSetters = ImmutableList.copyOf(psiFieldsForSetters); this.psiFieldsForConstructor = ImmutableList.copyOf(psiFieldsForConstructor); + this.allSelectedPsiFields = ImmutableList.copyOf(allSelectedPsiFields); } public List getFieldsForSetters() { @@ -22,4 +24,8 @@ public List getFieldsForSetters() { public List getFieldsForConstructor() { return psiFieldsForConstructor; } + + public List getAllSelectedFields() { + return allSelectedPsiFields; + } } diff --git a/src/test/java/pl/mjedynak/idea/plugins/builder/action/handler/DisplayChoosersRunnableTest.java b/src/test/java/pl/mjedynak/idea/plugins/builder/action/handler/DisplayChoosersRunnableTest.java index 59eab2d..c5dbfb4 100644 --- a/src/test/java/pl/mjedynak/idea/plugins/builder/action/handler/DisplayChoosersRunnableTest.java +++ b/src/test/java/pl/mjedynak/idea/plugins/builder/action/handler/DisplayChoosersRunnableTest.java @@ -128,7 +128,7 @@ public void shouldDisplayCreateBuilderAndMemberChooserDialogAndWriteBuilderWhenO given(createBuilderDialog.getMethodPrefix()).willReturn(methodPrefix); given(psiClassFromEditor.getAllFields()).willReturn(allFields); given(memberChooserDialogFactory.getMemberChooserDialog(selectedFields, project)).willReturn(memberChooserDialog); - given(psiFieldSelector.selectFieldsToIncludeInBuilder(psiClassFromEditor)).willReturn(selectedFields); + given(psiFieldSelector.selectFieldsToIncludeInBuilder(psiClassFromEditor, false)).willReturn(selectedFields); given(memberChooserDialog.getSelectedElements()).willReturn(selectedFields); // when diff --git a/src/test/java/pl/mjedynak/idea/plugins/builder/psi/BuilderPsiClassBuilderTest.java b/src/test/java/pl/mjedynak/idea/plugins/builder/psi/BuilderPsiClassBuilderTest.java index 22b6b2c..1f3938f 100644 --- a/src/test/java/pl/mjedynak/idea/plugins/builder/psi/BuilderPsiClassBuilderTest.java +++ b/src/test/java/pl/mjedynak/idea/plugins/builder/psi/BuilderPsiClassBuilderTest.java @@ -57,6 +57,7 @@ public class BuilderPsiClassBuilderTest { private BuilderContext context; private List psiFieldsForSetters = new ArrayList(); private List psiFieldsForConstructor = new ArrayList(); + private List allSelectedPsiFields = new ArrayList(); private String builderClassName = "BuilderClassName"; private String srcClassName = "ClassName"; @@ -73,6 +74,7 @@ public void setUp() { given(srcClass.getName()).willReturn(srcClassName); given(psiFieldsForBuilder.getFieldsForConstructor()).willReturn(psiFieldsForConstructor); given(psiFieldsForBuilder.getFieldsForSetters()).willReturn(psiFieldsForSetters); + given(psiFieldsForBuilder.getAllSelectedFields()).willReturn(allSelectedPsiFields); given(elementFactory.createClass(builderClassName)).willReturn(builderClass); given(builderClass.getModifierList()).willReturn(psiModifierList); context = new BuilderContext(project, psiFieldsForBuilder, targetDirectory, builderClassName, srcClass, "anyPrefix", false, false); @@ -186,6 +188,29 @@ public void shouldAddSetMethodsForFieldsFromBothLists() { verify(builderClass).add(methodForFieldForConstructor); } + @Test + public void shouldAddAllSelectedFieldAsSetterInInnerBuilder() { + // giver + PsiField selectedField = mock(PsiField.class); + allSelectedPsiFields.add(selectedField); + + String methodPrefix = "with"; + + PsiMethod setterMethod = mock(PsiMethod.class); + given(methodCreator.createMethod(selectedField, methodPrefix)).willReturn(setterMethod); + + BuilderPsiClassBuilder builder = psiClassBuilder.anInnerBuilder(context); + setField(builder, "methodCreator", methodCreator); + + given(builderClass.hasModifierProperty("static")).willReturn(true); + + // when + builder.withSetMethods(methodPrefix); + + // then + verify(builderClass).add(setterMethod); + } + @Test public void shouldAddButMethod() { // given @@ -223,6 +248,70 @@ public void shouldReturnBuilderObjectWithBuildMethodUsingSetterAndConstructor() assertThat(result).isNotNull(); } + @Test + public void constructorShouldHavePriorityOverSetter() { + // given + PsiField nameField = mock(PsiField.class); + PsiField ageField = mock(PsiField.class); + given(nameField.getName()).willReturn("name"); + given(ageField.getName()).willReturn("age"); + + psiFieldsForConstructor.clear(); + psiFieldsForSetters.clear(); + allSelectedPsiFields.clear(); + psiFieldsForConstructor.add(nameField); + psiFieldsForSetters.add(ageField); + + PsiMethod method = mock(PsiMethod.class); + String expectedCode = "public " + srcClassName + " build() { " + + srcClassName + " " + srcClassFieldName + " = new " + srcClassName + "(name);" + + srcClassFieldName + ".setAge(age);return " + srcClassFieldName + ";}"; + given(elementFactory.createMethodFromText(expectedCode, srcClass)).willReturn(method); + + given(builderClass.hasModifierProperty("static")).willReturn(true); + + // when + PsiClass result = psiClassBuilder.anInnerBuilder(context).build(); + + // then + verify(builderClass).add(method); + assertThat(result).isNotNull(); + + } + + @Test + public void setterShouldHavePriorityOverField() { + // given + PsiField nameField = mock(PsiField.class); + PsiField ageField = mock(PsiField.class); + given(nameField.getName()).willReturn("name"); + given(ageField.getName()).willReturn("age"); + + psiFieldsForConstructor.clear(); + psiFieldsForSetters.clear(); + allSelectedPsiFields.clear(); + psiFieldsForSetters.add(nameField); + allSelectedPsiFields.add(nameField); + allSelectedPsiFields.add(ageField); + + PsiMethod method = mock(PsiMethod.class); + String expectedCode = "public " + srcClassName + " build() { " + + srcClassName + " " + srcClassFieldName + " = new " + srcClassName + "();" + + srcClassFieldName + ".setName(name);" + + srcClassFieldName + ".age=this.age;return " + srcClassFieldName + ";}"; + given(elementFactory.createMethodFromText(expectedCode, srcClass)).willReturn(method); + + given(builderClass.hasModifierProperty("static")).willReturn(true); + + // when + PsiClass result = psiClassBuilder.anInnerBuilder(context).build(); + + // then + verify(builderClass).add(method); + assertThat(result).isNotNull(); + + } + @SuppressWarnings("unchecked") private void assertFieldsAreSet(BuilderPsiClassBuilder result) { assertThat(result).isSameAs(psiClassBuilder); diff --git a/src/test/java/pl/mjedynak/idea/plugins/builder/psi/PsiFieldSelectorTest.java b/src/test/java/pl/mjedynak/idea/plugins/builder/psi/PsiFieldSelectorTest.java index 9e02224..99fa61c 100644 --- a/src/test/java/pl/mjedynak/idea/plugins/builder/psi/PsiFieldSelectorTest.java +++ b/src/test/java/pl/mjedynak/idea/plugins/builder/psi/PsiFieldSelectorTest.java @@ -42,7 +42,7 @@ public void shouldSelectFieldIfVerifierAcceptsItAsSetInSetter() { given(psiFieldVerifier.isSetInSetterMethod(psiField, psiClass)).willReturn(true); // when - List result = psiFieldSelector.selectFieldsToIncludeInBuilder(psiClass); + List result = psiFieldSelector.selectFieldsToIncludeInBuilder(psiClass, false); // then assertThat(result).hasSize(1); @@ -54,7 +54,7 @@ public void shouldSelectFieldIfVerifierAcceptsItAsSetInConstructor() { given(psiFieldVerifier.isSetInConstructor(psiField, psiClass)).willReturn(true); // when - List result = psiFieldSelector.selectFieldsToIncludeInBuilder(psiClass); + List result = psiFieldSelector.selectFieldsToIncludeInBuilder(psiClass, false); // then assertThat(result).hasSize(1); @@ -67,10 +67,23 @@ public void shouldNotSelectFieldIfVerifierDoesNotAcceptsItAsSetInConstructorOrIn given(psiFieldVerifier.isSetInSetterMethod(psiField, psiClass)).willReturn(false); // when - List result = psiFieldSelector.selectFieldsToIncludeInBuilder(psiClass); + List result = psiFieldSelector.selectFieldsToIncludeInBuilder(psiClass, false); // then assertThat(result).hasSize(0); } + @Test + public void shouldSelectAllFieldsIfInnerBuilder() { + // given + given(psiFieldVerifier.isSetInConstructor(psiField, psiClass)).willReturn(false); + given(psiFieldVerifier.isSetInSetterMethod(psiField, psiClass)).willReturn(false); + + // when + List result = psiFieldSelector.selectFieldsToIncludeInBuilder(psiClass, true); + + // then + assertThat(result).hasSize(1); + } + } diff --git a/src/test/java/pl/mjedynak/idea/plugins/builder/psi/model/PsiFieldsForBuilderTest.java b/src/test/java/pl/mjedynak/idea/plugins/builder/psi/model/PsiFieldsForBuilderTest.java index bc2383d..317d82b 100644 --- a/src/test/java/pl/mjedynak/idea/plugins/builder/psi/model/PsiFieldsForBuilderTest.java +++ b/src/test/java/pl/mjedynak/idea/plugins/builder/psi/model/PsiFieldsForBuilderTest.java @@ -19,6 +19,7 @@ public class PsiFieldsForBuilderTest { private List psiFieldsForSetters; private List psiFieldsForConstructor; + private List allSelectedPsiFields; @Before public void setUp() { @@ -26,13 +27,17 @@ public void setUp() { psiFieldsForSetters.add(mock(PsiField.class)); psiFieldsForConstructor = new ArrayList(); psiFieldsForConstructor.add(mock(PsiField.class)); - psiFieldsForBuilder = new PsiFieldsForBuilder(psiFieldsForSetters, psiFieldsForConstructor); + allSelectedPsiFields = new ArrayList(); + allSelectedPsiFields.add(mock(PsiField.class)); + allSelectedPsiFields.add(mock(PsiField.class)); + psiFieldsForBuilder = new PsiFieldsForBuilder(psiFieldsForSetters, psiFieldsForConstructor, allSelectedPsiFields); } @Test - public void shouldGetTwoListsOfFields() { + public void shouldGetThreeListsOfFields() { assertThat(psiFieldsForBuilder.getFieldsForSetters()).isEqualTo(psiFieldsForSetters); assertThat(psiFieldsForBuilder.getFieldsForConstructor()).isEqualTo(psiFieldsForConstructor); + assertThat(psiFieldsForBuilder.getAllSelectedFields()).isEqualTo(allSelectedPsiFields); } @Test(expected = UnsupportedOperationException.class)