Skip to content

Commit

Permalink
Fix the issues reported by Sonar
Browse files Browse the repository at this point in the history
Fixes #135

Signed-off-by: Zbynek Cervinka <[email protected]>
  • Loading branch information
zcervink committed Jul 23, 2022
1 parent 810dc91 commit ecabace
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public class UITestRunner {
private static RemoteRobot remoteRobot = null;
private static Process ideProcess;
private static IntelliJVersion ideaVersion;
private static final String NEW_ITEM_PROPERTY = "New-ItemProperty";
private static final String NAME_PARAM = "-Name";
private static final String VALUE_PARAM = "-Value";

private UITestRunner() {}

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

try {
Process p1 = pb1.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.logging.Logger;

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

/**
* Welcome to IntelliJ IDEA dialog fixture
Expand All @@ -58,6 +57,7 @@
public class FlatWelcomeFrame extends CommonContainerFixture {
private static final Logger LOGGER = Logger.getLogger(FlatWelcomeFrame.class.getName());
private static final String PROJECTS_BUTTON = "Projects";
private static final String TIP_OF_THE_DAY = "Tip of the Day";
private final RemoteRobot remoteRobot;
private final IntelliJVersion intelliJVersion;
private final int ideaVersion;
Expand Down Expand Up @@ -170,11 +170,11 @@ public TipDialog openTipDialog() {
if (ideaVersion <= 20202) {
clickOnLink("Get Help");
HeavyWeightWindowFixture heavyWeightWindowFixture = find(HeavyWeightWindowFixture.class, Duration.ofSeconds(5));
heavyWeightWindowFixture.findText("Tip of the Day").click();
heavyWeightWindowFixture.findText(TIP_OF_THE_DAY).click();
} else if (ideaVersion <= 20203) {
actionLink("Help").click();
HeavyWeightWindowFixture heavyWeightWindowFixture = find(HeavyWeightWindowFixture.class, Duration.ofSeconds(5));
heavyWeightWindowFixture.findText("Tip of the Day").click();
heavyWeightWindowFixture.findText(TIP_OF_THE_DAY).click();
} else if (ideaVersion <= 20212) {
JListFixture jListFixture = remoteRobot.find(JListFixture.class, byXpath(XPathDefinitions.JBLIST));
jListFixture.findText("Learn IntelliJ IDEA").click();
Expand All @@ -184,7 +184,7 @@ public TipDialog openTipDialog() {
JTreeFixture jTreeFixture = remoteRobot.find(JTreeFixture.class, byXpath(XPathDefinitions.TREE));
jTreeFixture.findText("Learn IntelliJ IDEA").click();
FlatWelcomeFrame flatWelcomeFrame = remoteRobot.find(FlatWelcomeFrame.class);
flatWelcomeFrame.findText("Tip of the Day").click();
flatWelcomeFrame.findText(TIP_OF_THE_DAY).click();
}

return remoteRobot.find(TipDialog.class, Duration.ofSeconds(10));
Expand Down Expand Up @@ -239,9 +239,9 @@ private int projectsCount() {
// Works for IntelliJ Idea 2020.3+
private JButtonFixture welcomeFrameLink(String label) {
if (UtilsKt.hasAnyComponent(this, byXpath(XPathDefinitions.NEW_RECENT_PROJECT_PANEL))) {
return button(byXpath(XPathDefinitions.JBOptionButton(label)), Duration.ofSeconds(2));
return button(byXpath(XPathDefinitions.jBOptionButton(label)), Duration.ofSeconds(2));
}
return button(byXpath(XPathDefinitions.NonOpaquePanel(label)), Duration.ofSeconds(2));
return button(byXpath(XPathDefinitions.nonOpaquePanel(label)), Duration.ofSeconds(2));
}

private ComponentFixture ideErrorsIcon() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private List<RemoteText> getSearchResults() {
List<JListFixture> searchResults = jLists(JListFixture.Companion.byType());
if (searchResults.isEmpty()) {
return new ArrayList<>();
};
}
JListFixture searchResultsList = searchResults.get(0);
return searchResultsList.findAllText();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void selectNewProjectType(String projectType) {
*
* @param projectName project name
*/
@Override
public void setProjectName(String projectName) {
find(JTextFieldFixture.class, byXpath("//div[@class='JBTextField']")).setText(projectName);
}
Expand Down Expand Up @@ -104,7 +105,7 @@ public void setProjectSdkIfAvailable(String targetSdkName) {
projectJdkComboBox.click();
boolean popupOpenedPermanently = false;
try {
waitFor(Duration.ofSeconds(10), Duration.ofMillis(250), "HeavyWeightWindow still visible.", () -> noHeavyWeightWindowVisible());
waitFor(Duration.ofSeconds(10), Duration.ofMillis(250), "HeavyWeightWindow still visible.", this::noHeavyWeightWindowVisible);
} catch (WaitForConditionTimeoutException e) {
popupOpenedPermanently = true;
}
Expand Down Expand Up @@ -145,6 +146,6 @@ private kotlin.Pair<Boolean, CommonContainerFixture> didProjectSdkListLoadAllIte
}

private boolean noHeavyWeightWindowVisible() {
return remoteRobot.findAll(HeavyWeightWindowFixture.class).size() == 0;
return remoteRobot.findAll(HeavyWeightWindowFixture.class).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public abstract class AbstractToolWinPane extends CommonContainerFixture {
private final RemoteRobot remoteRobot;

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

private <T extends Fixture> T togglePane(String label, Class<T> fixtureClass, boolean openPane) {
protected <T extends Fixture> T togglePane(String label, Class<T> fixtureClass, boolean openPane) {
if ((!isPaneOpened(fixtureClass) && openPane)) {
clickOnStripeButton(label, false);
return find(fixtureClass, Duration.ofSeconds(10));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.data.RemoteComponent;
import com.intellij.remoterobot.fixtures.DefaultXpath;
import com.intellij.remoterobot.fixtures.Fixture;
import com.intellij.remoterobot.fixtures.FixtureName;
import com.intellij.remoterobot.fixtures.JButtonFixture;
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane.buildtoolpane.GradleBuildToolPane;
import com.redhat.devtools.intellij.commonuitest.fixtures.mainidewindow.toolwindowspane.buildtoolpane.MavenBuildToolPane;
import com.redhat.devtools.intellij.commonuitest.utils.constans.ButtonLabels;
Expand All @@ -26,7 +24,6 @@
import java.time.Duration;

import static com.intellij.remoterobot.search.locators.Locators.byXpath;
import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitFor;

/**
* Tool Windows Pane fixture
Expand All @@ -36,25 +33,24 @@
@DefaultXpath(by = "ToolWindowsPane type", xpath = XPathDefinitions.TOOL_WINDOWS_PANE)
@FixtureName(name = "Tool Windows Pane")
public class ToolWindowsPane extends AbstractToolWinPane {
private final RemoteRobot remoteRobot;

public ToolWindowsPane(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
super(remoteRobot, remoteComponent);
this.remoteRobot = remoteRobot;
}

/**
* Open project explorer
*
* @return the Project Explorer fixture
*/
@Override
public ProjectExplorer openProjectExplorer() {
return togglePane(ButtonLabels.PROJECT_STRIPE_BUTTON_LABEL, ProjectExplorer.class, true);
}

/**
* Close project explorer
*/
@Override
public void closeProjectExplorer() {
togglePane(ButtonLabels.PROJECT_STRIPE_BUTTON_LABEL, ProjectExplorer.class, false);
}
Expand All @@ -64,13 +60,15 @@ public void closeProjectExplorer() {
*
* @return the Maven Build Tool Pane fixture
*/
@Override
public MavenBuildToolPane openMavenBuildToolPane() {
return togglePane(ButtonLabels.MAVEN_STRIPE_BUTTON_LABEL, MavenBuildToolPane.class, true);
}

/**
* Close maven build tool pane
*/
@Override
public void closeMavenBuildToolPane() {
togglePane(ButtonLabels.MAVEN_STRIPE_BUTTON_LABEL, MavenBuildToolPane.class, false);
}
Expand All @@ -80,13 +78,15 @@ public void closeMavenBuildToolPane() {
*
* @return the Gradle Build Tool Pane fixture
*/
@Override
public GradleBuildToolPane openGradleBuildToolPane() {
return togglePane(ButtonLabels.GRADLE_STRIPE_BUTTON_LABEL, GradleBuildToolPane.class, true);
}

/**
* Close gradle build tool pane
*/
@Override
public void closeGradleBuildToolPane() {
togglePane(ButtonLabels.GRADLE_STRIPE_BUTTON_LABEL, GradleBuildToolPane.class, false);
}
Expand All @@ -98,6 +98,7 @@ public void closeGradleBuildToolPane() {
* @param isPaneOpened true if the pane is already opened
* @return fixture for the Stripe button
*/
@Override
public JButtonFixture stripeButton(String label, boolean isPaneOpened) {
if (isPaneOpened) {
if (label.equals(ButtonLabels.MAVEN_STRIPE_BUTTON_LABEL) || label.equals(ButtonLabels.GRADLE_STRIPE_BUTTON_LABEL)) {
Expand All @@ -108,38 +109,4 @@ public JButtonFixture stripeButton(String label, boolean isPaneOpened) {
}
return button(byXpath(XPathDefinitions.label(label)), Duration.ofSeconds(2));
}

private <T extends Fixture> T togglePane(String label, Class<T> fixtureClass, boolean openPane) {
if ((!isPaneOpened(fixtureClass) && openPane)) {
clickOnStripeButton(label, false);
return find(fixtureClass, Duration.ofSeconds(10));
} else if (isPaneOpened(fixtureClass) && !openPane) {
clickOnStripeButton(label, true);
}
return null;
}

private boolean isPaneOpened(Class<? extends Fixture> fixtureClass) {
ToolWindowsPane toolWindowsPane = remoteRobot.find(ToolWindowsPane.class, Duration.ofSeconds(10));
try {
toolWindowsPane.find(fixtureClass, Duration.ofSeconds(10));
return true;
} catch (WaitForConditionTimeoutException e) {
return false;
}
}

private void clickOnStripeButton(String label, boolean isPaneOpened) {
waitFor(Duration.ofSeconds(30), Duration.ofSeconds(2), "The '" + label + "' stripe button is not available.", () -> isStripeButtonAvailable(label, isPaneOpened));
remoteRobot.find(ToolWindowsPane.class, Duration.ofSeconds(10)).stripeButton(label, isPaneOpened).click();
}

private boolean isStripeButtonAvailable(String label, boolean isPaneOpened) {
try {
remoteRobot.find(ToolWindowsPane.class, Duration.ofSeconds(10)).stripeButton(label, isPaneOpened);
} catch (WaitForConditionTimeoutException e) {
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public static String label(String label) {
return "//div[@text='" + label + "']";
}

public static String JBOptionButton(String label) {
public static String jBOptionButton(String label) {
return "//div[@class='JBOptionButton' and @text='" + label + "']";
}

public static String NonOpaquePanel(String label) {
public static String nonOpaquePanel(String label) {
return "//div[@class='NonOpaquePanel'][./div[@text='" + label + "']]";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/
public class IdeInternalErrorUtils {
protected static final Logger LOGGER = Logger.getLogger(IdeInternalErrorUtils.class.getName());
private IdeInternalErrorUtils() {}

/**
* Clear internal IDE errors on Windows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static File takeScreenshot(RemoteRobot remoteRobot, String comment) {
Files.createDirectory(Paths.get(SCREENSHOT_LOCATION));
}
String screenshotFilename = getTimeNow("yyyy_MM_dd_HH_mm_ss");
String screenshotComment = comment == null || comment == "" ? "" : "_" + comment;
String screenshotComment = comment == null || comment.equals("") ? "" : "_" + comment;
String screenshotPathname = SCREENSHOT_LOCATION + screenshotFilename + screenshotComment + "." + FILETYPE;
File screenshotFile = new File(screenshotPathname);
ImageIO.write(screenshotBufferedImage, FILETYPE, screenshotFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.time.Duration;
import java.util.logging.Logger;

import static com.intellij.remoterobot.search.locators.Locators.byXpath;

/**
* Base class for all JUnit tests in the IntelliJ common UI test library
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class NewProjectDialogTest extends LibraryTestBase {
private static final String PLAIN_JAVA_PROJECT_NAME = "plain_java_project_name_test";
private static final String MORE_SETTINGS_SHOULD_BE_VISIBLE = "The 'More Settings' should be visible.";
private static final String MORE_SETTINGS_SHOULD_BE_HIDDEN = "The 'More Settings' should be hidden.";
private static final String ADVANCED_SETTINGS_SHOULD_BE_OPENED_MSG = "The 'Advanced Settings' section should be opened but is not";
private static final String ADVANCED_SETTINGS_SHOULD_BE_CLOSED_MSG = "The 'Advanced Settings' section should be closed but is not";
private static final String BUT_IS = "but is";

private NewProjectDialogWizard newProjectDialogWizard;
Expand Down Expand Up @@ -135,22 +137,22 @@ public void closeMoreSettingsTest() {
@EnabledIfSystemProperty(named = "uitestlib.idea.version", matches = "2020.|2021.")
public void openAdvancedSettingsTest() {
newProjectFirstPage.closeAdvanceSettings();
assertFalse(isAdvancedSettingsOpened(), "The 'Advanced Settings' section should be closed but is not");
assertFalse(isAdvancedSettingsOpened(), ADVANCED_SETTINGS_SHOULD_BE_CLOSED_MSG);
newProjectFirstPage.openAdvanceSettings();
assertTrue(isAdvancedSettingsOpened(), "The 'Advanced Settings' section should be opened but is not");
assertTrue(isAdvancedSettingsOpened(), ADVANCED_SETTINGS_SHOULD_BE_OPENED_MSG);
newProjectFirstPage.openAdvanceSettings();
assertTrue(isAdvancedSettingsOpened(), "The 'Advanced Settings' section should be opened but is not");
assertTrue(isAdvancedSettingsOpened(), ADVANCED_SETTINGS_SHOULD_BE_OPENED_MSG);
}

@Test
@EnabledIfSystemProperty(named = "uitestlib.idea.version", matches = "2020.|2021.")
public void closeAdvancedSettingsTest() {
newProjectFirstPage.openAdvanceSettings();
assertTrue(isAdvancedSettingsOpened(), "The 'Advanced Settings' section should be opened but is not");
assertTrue(isAdvancedSettingsOpened(), ADVANCED_SETTINGS_SHOULD_BE_OPENED_MSG);
newProjectFirstPage.closeAdvanceSettings();
assertFalse(isAdvancedSettingsOpened(), "The 'Advanced Settings' section should be closed but is not");
assertFalse(isAdvancedSettingsOpened(), ADVANCED_SETTINGS_SHOULD_BE_CLOSED_MSG);
newProjectFirstPage.closeAdvanceSettings();
assertFalse(isAdvancedSettingsOpened(), "The 'Advanced Settings' section should be closed but is not");
assertFalse(isAdvancedSettingsOpened(), ADVANCED_SETTINGS_SHOULD_BE_CLOSED_MSG);
}

@Test
Expand Down Expand Up @@ -370,7 +372,7 @@ public void selectNewProjectTypeTest() {

private void navigateToSetProjectNamePage(CreateCloseUtils.NewProjectType newProjectType) {
if (UITestRunner.getIdeaVersionInt() >= 20221) {
newProjectFirstPage.setBuildSystem(newProjectType.toString() == "Java" ? "IntelliJ" : newProjectType.toString());
newProjectFirstPage.setBuildSystem(newProjectType.toString().equals("Java") ? "IntelliJ" : newProjectType.toString());
return;
}
newProjectFirstPage.selectNewProjectType(newProjectType.toString());
Expand Down
Loading

0 comments on commit ecabace

Please sign in to comment.