Skip to content

Commit ead568a

Browse files
authored
Fix the issues reported by Sonar (#137)
Fixes #135 Signed-off-by: Zbynek Cervinka <[email protected]>
1 parent 09abb64 commit ead568a

File tree

11 files changed

+53
-69
lines changed

11 files changed

+53
-69
lines changed

src/main/java/com/redhat/devtools/intellij/commonuitest/UITestRunner.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public class UITestRunner {
5151
private static RemoteRobot remoteRobot = null;
5252
private static Process ideProcess;
5353
private static IntelliJVersion ideaVersion;
54+
private static final String NEW_ITEM_PROPERTY = "New-ItemProperty";
55+
private static final String NAME_PARAM = "-Name";
56+
private static final String VALUE_PARAM = "-Value";
57+
58+
private UITestRunner() {}
5459

5560
/**
5661
* Start the given version of IntelliJ Idea listening on the given port
@@ -221,9 +226,9 @@ private static void acceptAllTermsAndConditions() {
221226
String powershellLocation = "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe";
222227
String powershellPathParameter = "-Path";
223228
ProcessBuilder pb1 = new ProcessBuilder(powershellLocation, "New-Item", powershellPathParameter, registryPath, "-Force");
224-
ProcessBuilder pb2 = new ProcessBuilder(powershellLocation, "New-ItemProperty", powershellPathParameter, registryPath, "-Name", "accepted_version", "-Value", "'2.1'");
225-
ProcessBuilder pb3 = new ProcessBuilder(powershellLocation, "New-ItemProperty", powershellPathParameter, registryPath, "-Name", "euacommunity_accepted_version", "-Value", "'1.0'");
226-
ProcessBuilder pb4 = new ProcessBuilder(powershellLocation, "New-ItemProperty", powershellPathParameter, registryPath, "-Name", "eua_accepted_version", "-Value", "'1.2'");
229+
ProcessBuilder pb2 = new ProcessBuilder(powershellLocation, NEW_ITEM_PROPERTY, powershellPathParameter, registryPath, NAME_PARAM, "accepted_version", VALUE_PARAM, "'2.1'");
230+
ProcessBuilder pb3 = new ProcessBuilder(powershellLocation, NEW_ITEM_PROPERTY, powershellPathParameter, registryPath, NAME_PARAM, "euacommunity_accepted_version", VALUE_PARAM, "'1.0'");
231+
ProcessBuilder pb4 = new ProcessBuilder(powershellLocation, NEW_ITEM_PROPERTY, powershellPathParameter, registryPath, NAME_PARAM, "eua_accepted_version", VALUE_PARAM, "'1.2'");
227232

228233
try {
229234
Process p1 = pb1.start();

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/FlatWelcomeFrame.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.util.logging.Logger;
4747

4848
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
49-
import static com.redhat.devtools.intellij.commonuitest.utils.screenshot.ScreenshotUtils.takeScreenshot;
5049

5150
/**
5251
* Welcome to IntelliJ IDEA dialog fixture
@@ -58,6 +57,7 @@
5857
public class FlatWelcomeFrame extends CommonContainerFixture {
5958
private static final Logger LOGGER = Logger.getLogger(FlatWelcomeFrame.class.getName());
6059
private static final String PROJECTS_BUTTON = "Projects";
60+
private static final String TIP_OF_THE_DAY = "Tip of the Day";
6161
private final RemoteRobot remoteRobot;
6262
private final IntelliJVersion intelliJVersion;
6363
private final int ideaVersion;
@@ -170,11 +170,11 @@ public TipDialog openTipDialog() {
170170
if (ideaVersion <= 20202) {
171171
clickOnLink("Get Help");
172172
HeavyWeightWindowFixture heavyWeightWindowFixture = find(HeavyWeightWindowFixture.class, Duration.ofSeconds(5));
173-
heavyWeightWindowFixture.findText("Tip of the Day").click();
173+
heavyWeightWindowFixture.findText(TIP_OF_THE_DAY).click();
174174
} else if (ideaVersion <= 20203) {
175175
actionLink("Help").click();
176176
HeavyWeightWindowFixture heavyWeightWindowFixture = find(HeavyWeightWindowFixture.class, Duration.ofSeconds(5));
177-
heavyWeightWindowFixture.findText("Tip of the Day").click();
177+
heavyWeightWindowFixture.findText(TIP_OF_THE_DAY).click();
178178
} else if (ideaVersion <= 20212) {
179179
JListFixture jListFixture = remoteRobot.find(JListFixture.class, byXpath(XPathDefinitions.JBLIST));
180180
jListFixture.findText("Learn IntelliJ IDEA").click();
@@ -184,7 +184,7 @@ public TipDialog openTipDialog() {
184184
JTreeFixture jTreeFixture = remoteRobot.find(JTreeFixture.class, byXpath(XPathDefinitions.TREE));
185185
jTreeFixture.findText("Learn IntelliJ IDEA").click();
186186
FlatWelcomeFrame flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class);
187-
flatWelcomeFrame.findText("Tip of the Day").click();
187+
flatWelcomeFrame.findText(TIP_OF_THE_DAY).click();
188188
}
189189

190190
return remoteRobot.find(TipDialog.class, Duration.ofSeconds(10));

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/navigation/SearchEverywherePopup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private List<RemoteText> getSearchResults() {
8383
List<JListFixture> searchResults = jLists(JListFixture.Companion.byType());
8484
if (searchResults.isEmpty()) {
8585
return new ArrayList<>();
86-
};
86+
}
8787
JListFixture searchResultsList = searchResults.get(0);
8888
return searchResultsList.findAllText();
8989
}

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/project/pages/NewProjectFirstPage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void selectNewProjectType(String projectType) {
6565
*
6666
* @param projectName project name
6767
*/
68+
@Override
6869
public void setProjectName(String projectName) {
6970
find(JTextFieldFixture.class, byXpath("//div[@class='JBTextField']")).setText(projectName);
7071
}
@@ -104,7 +105,7 @@ public void setProjectSdkIfAvailable(String targetSdkName) {
104105
projectJdkComboBox.click();
105106
boolean popupOpenedPermanently = false;
106107
try {
107-
waitFor(Duration.ofSeconds(10), Duration.ofMillis(250), "HeavyWeightWindow still visible.", () -> noHeavyWeightWindowVisible());
108+
waitFor(Duration.ofSeconds(10), Duration.ofMillis(250), "HeavyWeightWindow still visible.", this::noHeavyWeightWindowVisible);
108109
} catch (WaitForConditionTimeoutException e) {
109110
popupOpenedPermanently = true;
110111
}
@@ -145,6 +146,6 @@ private kotlin.Pair<Boolean, CommonContainerFixture> didProjectSdkListLoadAllIte
145146
}
146147

147148
private boolean noHeavyWeightWindowVisible() {
148-
return remoteRobot.findAll(HeavyWeightWindowFixture.class).size() == 0;
149+
return remoteRobot.findAll(HeavyWeightWindowFixture.class).isEmpty();
149150
}
150151
}

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/toolwindowspane/AbstractToolWinPane.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
public abstract class AbstractToolWinPane extends CommonContainerFixture {
3636
private final RemoteRobot remoteRobot;
3737

38-
public AbstractToolWinPane(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
38+
protected AbstractToolWinPane(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
3939
super(remoteRobot, remoteComponent);
4040
this.remoteRobot = remoteRobot;
4141
}
@@ -106,7 +106,7 @@ public JButtonFixture stripeButton(String label, boolean isPaneOpened) {
106106
return button(byXpath("//div[@text='" + label + "']"), Duration.ofSeconds(2));
107107
}
108108

109-
private <T extends Fixture> T togglePane(String label, Class<T> fixtureClass, boolean openPane) {
109+
protected <T extends Fixture> T togglePane(String label, Class<T> fixtureClass, boolean openPane) {
110110
if ((!isPaneOpened(fixtureClass) && openPane)) {
111111
clickOnStripeButton(label, false);
112112
return find(fixtureClass, Duration.ofSeconds(10));

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/toolwindowspane/ToolWindowsPane.java

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
import com.intellij.remoterobot.RemoteRobot;
1414
import com.intellij.remoterobot.data.RemoteComponent;
1515
import com.intellij.remoterobot.fixtures.DefaultXpath;
16-
import com.intellij.remoterobot.fixtures.Fixture;
1716
import com.intellij.remoterobot.fixtures.FixtureName;
1817
import com.intellij.remoterobot.fixtures.JButtonFixture;
19-
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
2018
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane.buildtoolpane.GradleBuildToolPane;
2119
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane.buildtoolpane.MavenBuildToolPane;
2220
import com.redhat.devtools.intellij.commonuitest.utils.constants.ButtonLabels;
@@ -26,7 +24,6 @@
2624
import java.time.Duration;
2725

2826
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
29-
import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitFor;
3027

3128
/**
3229
* Tool Windows Pane fixture
@@ -36,25 +33,24 @@
3633
@DefaultXpath(by = "ToolWindowsPane type", xpath = XPathDefinitions.TOOL_WINDOWS_PANE)
3734
@FixtureName(name = "Tool Windows Pane")
3835
public class ToolWindowsPane extends AbstractToolWinPane {
39-
private final RemoteRobot remoteRobot;
40-
4136
public ToolWindowsPane(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
4237
super(remoteRobot, remoteComponent);
43-
this.remoteRobot = remoteRobot;
4438
}
4539

4640
/**
4741
* Open project explorer
4842
*
4943
* @return the Project Explorer fixture
5044
*/
45+
@Override
5146
public ProjectExplorer openProjectExplorer() {
5247
return togglePane(ButtonLabels.PROJECT_STRIPE_BUTTON_LABEL, ProjectExplorer.class, true);
5348
}
5449

5550
/**
5651
* Close project explorer
5752
*/
53+
@Override
5854
public void closeProjectExplorer() {
5955
togglePane(ButtonLabels.PROJECT_STRIPE_BUTTON_LABEL, ProjectExplorer.class, false);
6056
}
@@ -64,13 +60,15 @@ public void closeProjectExplorer() {
6460
*
6561
* @return the Maven Build Tool Pane fixture
6662
*/
63+
@Override
6764
public MavenBuildToolPane openMavenBuildToolPane() {
6865
return togglePane(ButtonLabels.MAVEN_STRIPE_BUTTON_LABEL, MavenBuildToolPane.class, true);
6966
}
7067

7168
/**
7269
* Close maven build tool pane
7370
*/
71+
@Override
7472
public void closeMavenBuildToolPane() {
7573
togglePane(ButtonLabels.MAVEN_STRIPE_BUTTON_LABEL, MavenBuildToolPane.class, false);
7674
}
@@ -80,13 +78,15 @@ public void closeMavenBuildToolPane() {
8078
*
8179
* @return the Gradle Build Tool Pane fixture
8280
*/
81+
@Override
8382
public GradleBuildToolPane openGradleBuildToolPane() {
8483
return togglePane(ButtonLabels.GRADLE_STRIPE_BUTTON_LABEL, GradleBuildToolPane.class, true);
8584
}
8685

8786
/**
8887
* Close gradle build tool pane
8988
*/
89+
@Override
9090
public void closeGradleBuildToolPane() {
9191
togglePane(ButtonLabels.GRADLE_STRIPE_BUTTON_LABEL, GradleBuildToolPane.class, false);
9292
}
@@ -98,6 +98,7 @@ public void closeGradleBuildToolPane() {
9898
* @param isPaneOpened true if the pane is already opened
9999
* @return fixture for the Stripe button
100100
*/
101+
@Override
101102
public JButtonFixture stripeButton(String label, boolean isPaneOpened) {
102103
if (isPaneOpened) {
103104
if (label.equals(ButtonLabels.MAVEN_STRIPE_BUTTON_LABEL) || label.equals(ButtonLabels.GRADLE_STRIPE_BUTTON_LABEL)) {
@@ -108,38 +109,4 @@ public JButtonFixture stripeButton(String label, boolean isPaneOpened) {
108109
}
109110
return button(byXpath(XPathDefinitions.label(label)), Duration.ofSeconds(2));
110111
}
111-
112-
private <T extends Fixture> T togglePane(String label, Class<T> fixtureClass, boolean openPane) {
113-
if ((!isPaneOpened(fixtureClass) && openPane)) {
114-
clickOnStripeButton(label, false);
115-
return find(fixtureClass, Duration.ofSeconds(10));
116-
} else if (isPaneOpened(fixtureClass) && !openPane) {
117-
clickOnStripeButton(label, true);
118-
}
119-
return null;
120-
}
121-
122-
private boolean isPaneOpened(Class<? extends Fixture> fixtureClass) {
123-
ToolWindowsPane toolWindowsPane = remoteRobot.find(ToolWindowsPane.class, Duration.ofSeconds(10));
124-
try {
125-
toolWindowsPane.find(fixtureClass, Duration.ofSeconds(10));
126-
return true;
127-
} catch (WaitForConditionTimeoutException e) {
128-
return false;
129-
}
130-
}
131-
132-
private void clickOnStripeButton(String label, boolean isPaneOpened) {
133-
waitFor(Duration.ofSeconds(30), Duration.ofSeconds(2), "The '" + label + "' stripe button is not available.", () -> isStripeButtonAvailable(label, isPaneOpened));
134-
remoteRobot.find(ToolWindowsPane.class, Duration.ofSeconds(10)).stripeButton(label, isPaneOpened).click();
135-
}
136-
137-
private boolean isStripeButtonAvailable(String label, boolean isPaneOpened) {
138-
try {
139-
remoteRobot.find(ToolWindowsPane.class, Duration.ofSeconds(10)).stripeButton(label, isPaneOpened);
140-
} catch (WaitForConditionTimeoutException e) {
141-
return false;
142-
}
143-
return true;
144-
}
145112
}

src/main/java/com/redhat/devtools/intellij/commonuitest/utils/internalerror/IdeInternalErrorUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*/
3131
public class IdeInternalErrorUtils {
3232
protected static final Logger LOGGER = Logger.getLogger(IdeInternalErrorUtils.class.getName());
33+
private IdeInternalErrorUtils() {}
3334

3435
/**
3536
* Clear internal IDE errors on Windows

src/main/java/com/redhat/devtools/intellij/commonuitest/utils/screenshot/ScreenshotUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static File takeScreenshot(RemoteRobot remoteRobot, String comment) {
5353
Files.createDirectory(Paths.get(SCREENSHOT_LOCATION));
5454
}
5555
String screenshotFilename = getTimeNow("yyyy_MM_dd_HH_mm_ss");
56-
String screenshotComment = comment == null || comment == "" ? "" : "_" + comment;
56+
String screenshotComment = comment == null || comment.equals("") ? "" : "_" + comment;
5757
String screenshotPathname = SCREENSHOT_LOCATION + screenshotFilename + screenshotComment + "." + FILETYPE;
5858
File screenshotFile = new File(screenshotPathname);
5959
ImageIO.write(screenshotBufferedImage, FILETYPE, screenshotFile);

src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/LibraryTestBase.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import java.time.Duration;
2424
import java.util.logging.Logger;
2525

26-
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
27-
2826
/**
2927
* Base class for all JUnit tests in the IntelliJ common UI test library
3028
*

src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/fixtures/test/dialogs/project_manipulation/NewProjectDialogTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public class NewProjectDialogTest extends LibraryTestBase {
5454
private static final String PLAIN_JAVA_PROJECT_NAME = "plain_java_project_name_test";
5555
private static final String MORE_SETTINGS_SHOULD_BE_VISIBLE = "The 'More Settings' should be visible.";
5656
private static final String MORE_SETTINGS_SHOULD_BE_HIDDEN = "The 'More Settings' should be hidden.";
57+
private static final String ADVANCED_SETTINGS_SHOULD_BE_OPENED_MSG = "The 'Advanced Settings' section should be opened but is not";
58+
private static final String ADVANCED_SETTINGS_SHOULD_BE_CLOSED_MSG = "The 'Advanced Settings' section should be closed but is not";
5759
private static final String BUT_IS = "but is";
5860

5961
private NewProjectDialogWizard newProjectDialogWizard;
@@ -135,22 +137,22 @@ public void closeMoreSettingsTest() {
135137
@EnabledIfSystemProperty(named = "uitestlib.idea.version", matches = "2020.|2021.")
136138
public void openAdvancedSettingsTest() {
137139
newProjectFirstPage.closeAdvanceSettings();
138-
assertFalse(isAdvancedSettingsOpened(), "The 'Advanced Settings' section should be closed but is not");
140+
assertFalse(isAdvancedSettingsOpened(), ADVANCED_SETTINGS_SHOULD_BE_CLOSED_MSG);
139141
newProjectFirstPage.openAdvanceSettings();
140-
assertTrue(isAdvancedSettingsOpened(), "The 'Advanced Settings' section should be opened but is not");
142+
assertTrue(isAdvancedSettingsOpened(), ADVANCED_SETTINGS_SHOULD_BE_OPENED_MSG);
141143
newProjectFirstPage.openAdvanceSettings();
142-
assertTrue(isAdvancedSettingsOpened(), "The 'Advanced Settings' section should be opened but is not");
144+
assertTrue(isAdvancedSettingsOpened(), ADVANCED_SETTINGS_SHOULD_BE_OPENED_MSG);
143145
}
144146

145147
@Test
146148
@EnabledIfSystemProperty(named = "uitestlib.idea.version", matches = "2020.|2021.")
147149
public void closeAdvancedSettingsTest() {
148150
newProjectFirstPage.openAdvanceSettings();
149-
assertTrue(isAdvancedSettingsOpened(), "The 'Advanced Settings' section should be opened but is not");
151+
assertTrue(isAdvancedSettingsOpened(), ADVANCED_SETTINGS_SHOULD_BE_OPENED_MSG);
150152
newProjectFirstPage.closeAdvanceSettings();
151-
assertFalse(isAdvancedSettingsOpened(), "The 'Advanced Settings' section should be closed but is not");
153+
assertFalse(isAdvancedSettingsOpened(), ADVANCED_SETTINGS_SHOULD_BE_CLOSED_MSG);
152154
newProjectFirstPage.closeAdvanceSettings();
153-
assertFalse(isAdvancedSettingsOpened(), "The 'Advanced Settings' section should be closed but is not");
155+
assertFalse(isAdvancedSettingsOpened(), ADVANCED_SETTINGS_SHOULD_BE_CLOSED_MSG);
154156
}
155157

156158
@Test
@@ -370,7 +372,7 @@ public void selectNewProjectTypeTest() {
370372

371373
private void navigateToSetProjectNamePage(CreateCloseUtils.NewProjectType newProjectType) {
372374
if (UITestRunner.getIdeaVersionInt() >= 20221) {
373-
newProjectFirstPage.setBuildSystem(newProjectType.toString() == "Java" ? "IntelliJ" : newProjectType.toString());
375+
newProjectFirstPage.setBuildSystem(newProjectType.toString().equals("Java") ? "IntelliJ" : newProjectType.toString());
374376
return;
375377
}
376378
newProjectFirstPage.selectNewProjectType(newProjectType.toString());

0 commit comments

Comments
 (0)