Skip to content

Commit 29df17b

Browse files
author
Sergiy Zhovnir
committed
#issue-83 Fixing static tests
1 parent 7d3f5dd commit 29df17b

File tree

8 files changed

+53
-46
lines changed

8 files changed

+53
-46
lines changed

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
</component>
222222
</children>
223223
</grid>
224-
<grid id="1987e" binding="toolbarOptionsPanel" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
224+
<grid id="1987e" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
225225
<margin top="0" left="0" bottom="0" right="0"/>
226226
<constraints>
227227
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@
3636
import javax.swing.JTextField;
3737
import javax.swing.KeyStroke;
3838

39+
@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports", "PMD.UnusedPrivateMethod"})
3940
public class NewUiComponentGridDialog extends AbstractDialog {
4041
private final Project project;
4142
private final String moduleName;
4243
private final NewUiComponentGridDialogValidator validator;
43-
private ArrayList<String> collectionOptions;
44+
private List<String> collectionOptions;
4445
private JPanel contentPanel;
4546
private JButton buttonOK;
4647
private JButton buttonCancel;
@@ -58,7 +59,6 @@ public class NewUiComponentGridDialog extends AbstractDialog {
5859
private JTextField providerClassName;
5960
private JTextField dataProviderParentDirectory;
6061
private JTextField acl;
61-
private JPanel toolbarOptionsPanel;
6262
private JLabel aclLabel;
6363
private JLabel collectionLabel;
6464

@@ -185,17 +185,17 @@ private void addActionListeners() {
185185
}
186186

187187
private void generateFile() {
188-
final UiComponentGridDataProviderGenerator DataProviderGenerator;
189-
DataProviderGenerator = new UiComponentGridDataProviderGenerator(
188+
final UiComponentGridDataProviderGenerator dataProviderGenerator;
189+
dataProviderGenerator = new UiComponentGridDataProviderGenerator(
190190
getGridDataProviderData(),
191191
getModuleName(),
192192
project
193193
);
194-
UiComponentGridXmlGenerator gridXmlGenerator = new UiComponentGridXmlGenerator(
194+
final UiComponentGridXmlGenerator gridXmlGenerator = new UiComponentGridXmlGenerator(
195195
getUiComponentGridData(),
196196
project
197197
);
198-
DataProviderGenerator.generate(NewUiComponentGridAction.ACTION_NAME);
198+
dataProviderGenerator.generate(NewUiComponentGridAction.ACTION_NAME);
199199
gridXmlGenerator.generate(NewUiComponentGridAction.ACTION_NAME, true);
200200
}
201201

@@ -239,7 +239,7 @@ private List<String> getCollectionOptions() {
239239
if (this.collectionOptions == null) {
240240
this.collectionOptions = new ArrayList<>();
241241
this.collectionOptions.add("");
242-
GetResourceCollections getResourceCollections = GetResourceCollections.getInstance(
242+
final GetResourceCollections getResourceCollections = GetResourceCollections.getInstance(
243243
this.project
244244
);
245245

src/com/magento/idea/magento2plugin/actions/generation/dialog/validator/NewUiComponentGridDialogValidator.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@
1616
import com.magento.idea.magento2plugin.util.RegExUtil;
1717
import javax.swing.JOptionPane;
1818

19-
@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.NonThreadSafeSingleton"})
19+
@SuppressWarnings({
20+
"PMD.OnlyOneReturn",
21+
"PMD.NonThreadSafeSingleton",
22+
"PMD.LongMethodRule",
23+
"PMD.CyclomaticComplexity",
24+
"PMD.NPathComplexity"
25+
})
2026
public class NewUiComponentGridDialogValidator {
2127
private static final String DATA_PROVIDER_NAME = "Data Provider Name";
28+
private static final String NOT_EMPTY = "validator.notEmpty";
2229
private static NewUiComponentGridDialogValidator instance;
2330
private final ValidatorBundle validatorBundle;
2431
private final CommonBundle commonBundle;
@@ -61,7 +68,7 @@ private boolean validateUiComponentData(final UiComponentGridData uiComponentGri
6168

6269
if (name.length() == 0) {
6370
final String errorMessage = this.validatorBundle.message(
64-
"validator.notEmpty",
71+
NOT_EMPTY,
6572
"Name"
6673
);
6774
JOptionPane.showMessageDialog(
@@ -93,7 +100,7 @@ private boolean validateUiComponentData(final UiComponentGridData uiComponentGri
93100

94101
if (idFieldName.length() == 0) {
95102
final String errorMessage = this.validatorBundle.message(
96-
"validator.notEmpty",
103+
NOT_EMPTY,
97104
"Entity ID field"
98105
);
99106
JOptionPane.showMessageDialog(
@@ -126,7 +133,7 @@ private boolean validateUiComponentData(final UiComponentGridData uiComponentGri
126133

127134
if (area.length() == 0) {
128135
final String errorMessage = this.validatorBundle.message(
129-
"validator.notEmpty",
136+
NOT_EMPTY,
130137
"Area"
131138
);
132139
JOptionPane.showMessageDialog(
@@ -143,7 +150,7 @@ private boolean validateUiComponentData(final UiComponentGridData uiComponentGri
143150

144151
if (area.equals(Areas.adminhtml.toString()) && acl.length() == 0) {
145152
final String errorMessage = this.validatorBundle.message(
146-
"validator.notEmpty",
153+
NOT_EMPTY,
147154
"Acl"
148155
);
149156
JOptionPane.showMessageDialog(
@@ -165,7 +172,7 @@ private boolean validateDataProviderData(final UiComponentGridDataProviderData p
165172

166173
if (type.length() == 0) {
167174
final String errorMessage = this.validatorBundle.message(
168-
"validator.notEmpty",
175+
NOT_EMPTY,
169176
"Data Provider Type"
170177
);
171178
JOptionPane.showMessageDialog(
@@ -184,7 +191,7 @@ private boolean validateDataProviderData(final UiComponentGridDataProviderData p
184191
&& collection.length() == 0
185192
) {
186193
final String errorMessage = this.validatorBundle.message(
187-
"validator.notEmpty",
194+
NOT_EMPTY,
188195
"Data Provider Collection"
189196
);
190197
JOptionPane.showMessageDialog(
@@ -201,7 +208,7 @@ private boolean validateDataProviderData(final UiComponentGridDataProviderData p
201208

202209
if (name.length() == 0) {
203210
final String errorMessage = this.validatorBundle.message(
204-
"validator.notEmpty",
211+
NOT_EMPTY,
205212
DATA_PROVIDER_NAME
206213
);
207214
JOptionPane.showMessageDialog(
@@ -265,7 +272,7 @@ private boolean validateDataProviderData(final UiComponentGridDataProviderData p
265272

266273
if (parentDirectory.length() == 0) {
267274
final String errorMessage = validatorBundle.message(
268-
"validator.notEmpty",
275+
NOT_EMPTY,
269276
"Data Provider Parent Directory"
270277
);
271278
JOptionPane.showMessageDialog(

src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridDataProviderGenerator.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727

2828
@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.DataflowAnomalyAnalysis"})
2929
public class UiComponentGridDataProviderGenerator extends FileGenerator {
30-
final UiComponentGridDataProviderData uiComponentGridDataProviderData;
31-
final Project project;
32-
final DirectoryGenerator directoryGenerator;
33-
final FileFromTemplateGenerator fileFromTemplateGenerator;
34-
final ValidatorBundle validatorBundle;
35-
final CommonBundle commonBundle;
36-
final String moduleName;
37-
final GetFirstClassOfFile getFirstClassOfFile;
30+
private final UiComponentGridDataProviderData uiComponentGridDataProviderData;
31+
private final Project project;
32+
private final DirectoryGenerator directoryGenerator;
33+
private final FileFromTemplateGenerator fileFromTemplateGenerator;
34+
private final ValidatorBundle validatorBundle;
35+
private final CommonBundle commonBundle;
36+
private final String moduleName;
37+
private final GetFirstClassOfFile getFirstClassOfFile;
3838

3939
/**
4040
* Ui component grid data provider constructor.
@@ -61,7 +61,7 @@ public UiComponentGridDataProviderGenerator(
6161
}
6262

6363
@Override
64-
public PsiFile generate(String actionName) {
64+
public PsiFile generate(final String actionName) {
6565
final PsiFile[] dataProviderFiles = new PsiFile[1];
6666

6767
WriteCommandAction.runWriteCommandAction(project, () -> {
@@ -108,7 +108,7 @@ public PsiFile generate(String actionName) {
108108
}
109109

110110
@Override
111-
protected void fillAttributes(Properties attributes) {
111+
protected void fillAttributes(final Properties attributes) {
112112
attributes.setProperty("NAMESPACE", uiComponentGridDataProviderData.getNamespace());
113113
attributes.setProperty("CLASS_NAME", uiComponentGridDataProviderData.getName());
114114
final String dataProviderType = uiComponentGridDataProviderData.getType();

src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGenerator.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import java.util.Properties;
2020

2121
public class UiComponentGridXmlGenerator extends FileGenerator {
22+
public static final String TRUE = "true";
2223
private final UiComponentGridData uiComponentGridData;
23-
private final Project project;
2424
private final DirectoryGenerator directoryGenerator;
2525
private final ModuleIndex moduleIndex;
2626
private final FileFromTemplateGenerator fileFromTemplateGenerator;
@@ -38,14 +38,13 @@ public UiComponentGridXmlGenerator(
3838
super(project);
3939

4040
this.uiComponentGridData = uiComponentGridData;
41-
this.project = project;
4241
this.directoryGenerator = DirectoryGenerator.getInstance();
4342
this.moduleIndex = ModuleIndex.getInstance(project);
4443
this.fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project);
4544
}
4645

4746
@Override
48-
public PsiFile generate(String actionName) {
47+
public PsiFile generate(final String actionName) {
4948
final String moduleName = this.uiComponentGridData.getModuleName();
5049
PsiDirectory uiComponentDirectory = this.moduleIndex.getModuleDirectoryByModuleName(
5150
moduleName
@@ -64,7 +63,7 @@ public PsiFile generate(String actionName) {
6463
);
6564
}
6665

67-
UiComponentGridXml uiGridXml = new UiComponentGridXml(uiComponentGridData.getName());
66+
final UiComponentGridXml uiGridXml = new UiComponentGridXml(uiComponentGridData.getName());
6867

6968
return this.fileFromTemplateGenerator.generate(
7069
uiGridXml,
@@ -75,7 +74,7 @@ public PsiFile generate(String actionName) {
7574
}
7675

7776
@Override
78-
protected void fillAttributes(Properties attributes) {
77+
protected void fillAttributes(final Properties attributes) {
7978
attributes.setProperty("NAME", uiComponentGridData.getName());
8079
attributes.setProperty("ID_FIELD_NAME", uiComponentGridData.getIdFieldName());
8180
attributes.setProperty("ID_FIELD_NAME", uiComponentGridData.getIdFieldName());
@@ -84,26 +83,26 @@ protected void fillAttributes(Properties attributes) {
8483
final UiComponentGridToolbarData toolbarData = uiComponentGridData.getGridToolbarData();
8584

8685
if (toolbarData.isAddToolbar()) {
87-
attributes.setProperty("TOOLBAR", "true");
86+
attributes.setProperty("TOOLBAR", TRUE);
8887

8988
if (toolbarData.isAddBookmarks()) {
90-
attributes.setProperty("BOOKMARKS", "true");
89+
attributes.setProperty("BOOKMARKS", TRUE);
9190
}
9291

9392
if (toolbarData.isAddColumnsControls()) {
94-
attributes.setProperty("COLUMNS_CONTROLS", "true");
93+
attributes.setProperty("COLUMNS_CONTROLS", TRUE);
9594
}
9695

9796
if (toolbarData.isAddFulltextSearch()) {
98-
attributes.setProperty("FULLTEXT_SEARCH", "true");
97+
attributes.setProperty("FULLTEXT_SEARCH", TRUE);
9998
}
10099

101100
if (toolbarData.isAddListingFilters()) {
102-
attributes.setProperty("LISTING_FILTERS", "true");
101+
attributes.setProperty("LISTING_FILTERS", TRUE);
103102
}
104103

105104
if (toolbarData.isAddListingPaging()) {
106-
attributes.setProperty("LISTING_PAGING", "true");
105+
attributes.setProperty("LISTING_PAGING", TRUE);
107106
}
108107
}
109108
}

src/com/magento/idea/magento2plugin/magento/files/UiComponentGridDataProviderPhp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ public String getFileName() {
6565

6666
@Override
6767
public String getTemplate() {
68-
if (providerType.equals("collection")) {
68+
if (providerType.equals(COLLECTION_TYPE)) {
6969
return COLLECTION_TEMPLATE;
7070
}
7171

72-
if (providerType.equals("custom")) {
72+
if (providerType.equals(CUSTOM_TYPE)) {
7373
return CUSTOM_TEMPLATE;
7474
}
7575

src/com/magento/idea/magento2plugin/util/magento/GetResourceCollections.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Collection;
1313
import java.util.List;
1414

15+
@SuppressWarnings({"PMD.NonThreadSafeSingleton", "PMD.FieldNamingConventions"})
1516
public class GetResourceCollections {
1617
private static final String ABSTRACT_COLLECTION_FQN =
1718
"Magento\\Framework\\Model\\ResourceModel\\Db\\Collection\\AbstractCollection";
@@ -25,7 +26,7 @@ public class GetResourceCollections {
2526
*
2627
* @return GetResourceCollections
2728
*/
28-
public static GetResourceCollections getInstance(Project project) {
29+
public static GetResourceCollections getInstance(final Project project) {
2930
if (null == INSTANCE) {
3031
INSTANCE = new GetResourceCollections();
3132
}
@@ -39,14 +40,14 @@ public static GetResourceCollections getInstance(Project project) {
3940
* @return List
4041
*/
4142
public List<PhpClass> execute() {
42-
PhpIndex phpIndex = PhpIndex.getInstance(project);
43-
Collection<PhpClass> collections = phpIndex.getAllSubclasses(ABSTRACT_COLLECTION_FQN);
44-
List<PhpClass> resourceCollectionList = new ArrayList<>();
43+
final PhpIndex phpIndex = PhpIndex.getInstance(project);
44+
final Collection<PhpClass> collections = phpIndex.getAllSubclasses(ABSTRACT_COLLECTION_FQN);
4545

4646
if (collections.isEmpty()) {
4747
return null;
4848
}
4949

50+
final List<PhpClass> resourceCollectionList = new ArrayList<>();
5051
resourceCollectionList.addAll(collections);
5152

5253
return resourceCollectionList;

tests/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentGridXmlGeneratorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ private PsiFile generateComponentGridXml(
7373
ACL,
7474
uiGridToolbarData
7575
);
76-
final UiComponentGridXmlGenerator UiGridXmlGenerator = new UiComponentGridXmlGenerator(
76+
final UiComponentGridXmlGenerator uiGridXmlGenerator = new UiComponentGridXmlGenerator(
7777
uiGridData,
7878
project
7979
);
8080

81-
return UiGridXmlGenerator.generate("test");
81+
return uiGridXmlGenerator.generate("test");
8282
}
8383

8484
/**

0 commit comments

Comments
 (0)