Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Fixed "Do not automatically update..." because check box has been
Browse files Browse the repository at this point in the history
removed. Added test for Global Update Policy.

Signed-off-by: Oleksii Korniienko <[email protected]>
  • Loading branch information
olkornii committed Sep 6, 2023
1 parent 5f99e5f commit 5427600
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.reddeer.core.reference.ReferencedComposite;
import org.eclipse.reddeer.jface.preference.PreferencePage;
import org.eclipse.reddeer.swt.impl.button.CheckBox;
import org.eclipse.reddeer.swt.impl.combo.LabeledCombo;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;

Expand All @@ -34,6 +35,7 @@ public class MavenPreferencePage extends PreferencePage {
private static final String DOWNLOAD_REPO_INDEX_UPDATES_ON_STARTUP="Download repository index updates on startup";
private static final String UPDATE_MAVEN_PROJECTS_ON_STARTUP="Update Maven projects on startup";
private static final String HIDE_FOLDERS_OF_PHYSICALLY_NESTED_MODULES="Hide folders of physically nested modules (experimental)";
private static final String GLOBAL_UPDATE_POLICY="Global Update Policy:";

/**
* Constructs the preference page with "Maven".
Expand Down Expand Up @@ -67,7 +69,11 @@ public MavenPreferencePage setOffline(boolean check) {
* @return true, if is do not auto update deps checked
*/
public boolean isDoNotAutoUpdateDepsChecked() {
return new CheckBox(this, MavenPreferencePage.DO_NOT_AUTO_UPDATE_DEPS).isChecked();
try {
return new CheckBox(this, MavenPreferencePage.DO_NOT_AUTO_UPDATE_DEPS).isChecked();
} catch (org.eclipse.reddeer.core.exception.CoreLayerException e) { // there is no CheckBox "Do Not Auto update..." starting 2023-09-M3 Eclipse
return "Never".equals(getGlobalUpdatePolicy());
}
}

/**
Expand All @@ -76,7 +82,15 @@ public boolean isDoNotAutoUpdateDepsChecked() {
* @param check the new do not auto update deps
*/
public MavenPreferencePage setDoNotAutoUpdateDeps(boolean check) {
new CheckBox(this, MavenPreferencePage.DO_NOT_AUTO_UPDATE_DEPS).toggle(check);
try {
new CheckBox(this, MavenPreferencePage.DO_NOT_AUTO_UPDATE_DEPS).toggle(check);
} catch (org.eclipse.reddeer.core.exception.CoreLayerException e) { // there is no CheckBox "Do Not Auto update..." starting 2023-09-M3 Eclipse
if (check) {
setGlobalUpdatePolicy("Never");
} else {
setGlobalUpdatePolicy("Default");
}
}
return this;
}

Expand Down Expand Up @@ -212,4 +226,23 @@ public MavenPreferencePage setHideFoldersOfPhysicalyNestedModules(boolean check)
new CheckBox(this, MavenPreferencePage.HIDE_FOLDERS_OF_PHYSICALLY_NESTED_MODULES).toggle(check);
return this;
}

/**
* Returns String with selected Global Update Policy combo item .
*
* @return selected Global Update Policy combo item
*/
public String getGlobalUpdatePolicy() {
return new LabeledCombo(MavenPreferencePage.GLOBAL_UPDATE_POLICY).getSelection();
}

/**
* Sets Global Update Policy .
*
* @param updatePolicyType type of Global Update Policy to select
*/
public MavenPreferencePage setGlobalUpdatePolicy(String updatePolicyType) {
new LabeledCombo(MavenPreferencePage.GLOBAL_UPDATE_POLICY).setSelection(updatePolicyType);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,33 @@ public class MavenPreferencePageTest {
private WorkbenchPreferenceDialog preferencesDialog = new WorkbenchPreferenceDialog();

private MavenPreferencePage mavenPreferencePage = new MavenPreferencePage(preferencesDialog);

@Test
public void checkGlobalUpdatePolicy() {
preferencesDialog.open();
preferencesDialog.select(mavenPreferencePage);

mavenPreferencePage.setGlobalUpdatePolicy("Always");
assertTrue("Always".equals(mavenPreferencePage.getGlobalUpdatePolicy()));
mavenPreferencePage.setGlobalUpdatePolicy("Daily");
assertTrue("Daily".equals(mavenPreferencePage.getGlobalUpdatePolicy()));
mavenPreferencePage.setGlobalUpdatePolicy("Hourly");
assertTrue("Hourly".equals(mavenPreferencePage.getGlobalUpdatePolicy()));;
mavenPreferencePage.setGlobalUpdatePolicy("Default");
assertTrue("Default".equals(mavenPreferencePage.getGlobalUpdatePolicy()));
mavenPreferencePage.setGlobalUpdatePolicy("Never");
assertTrue("Never".equals(mavenPreferencePage.getGlobalUpdatePolicy()));

preferencesDialog.cancel();
}

@Test
public void checkAllPreferences() {
preferencesDialog.open();
preferencesDialog.select(mavenPreferencePage);

mavenPreferencePage.setDebugOutput(true);
// mavenPreferencePage.setDoNotAutoUpdateDeps(true); # is not a part of 2023-09 Eclipse
mavenPreferencePage.setDoNotAutoUpdateDeps(true);
mavenPreferencePage.setDownloadArtifactJavadoc(true);
mavenPreferencePage.setDownloadArtifactSources(true);
mavenPreferencePage.setDownloadRepoIndexOnStartup(true);
Expand All @@ -43,14 +62,14 @@ public void checkAllPreferences() {
mavenPreferencePage.setUpdateMavenProjectsOnStartup(true);

assertTrue(mavenPreferencePage.isDebugOutputChecked());
// assertTrue(mavenPreferencePage.isDoNotAutoUpdateDepsChecked()); # is not a part of 2023-09 Eclipse
assertTrue(mavenPreferencePage.isDoNotAutoUpdateDepsChecked());
assertTrue(mavenPreferencePage.isDownloadArtifactJavadocChecked());
assertTrue(mavenPreferencePage.isDownloadArtifactSourcesChecked());
assertTrue(mavenPreferencePage.isDownloadRepoIndexOnStartupChecked());
assertTrue(mavenPreferencePage.isHideFoldersOfPhysicalyNestedModulesChecked());
assertTrue(mavenPreferencePage.isOfflineChecked());
assertTrue(mavenPreferencePage.isUpdateMavenProjectsOnStartupChecked());

preferencesDialog.cancel();
}

Expand All @@ -60,7 +79,7 @@ public void uncheckAllPreferences() {
preferencesDialog.select(mavenPreferencePage);

mavenPreferencePage.setDebugOutput(false);
// mavenPreferencePage.setDoNotAutoUpdateDeps(false); # is not a part of 2023-09 Eclipse
mavenPreferencePage.setDoNotAutoUpdateDeps(false);
mavenPreferencePage.setDownloadArtifactJavadoc(false);
mavenPreferencePage.setDownloadArtifactSources(false);
mavenPreferencePage.setDownloadRepoIndexOnStartup(false);
Expand All @@ -69,7 +88,7 @@ public void uncheckAllPreferences() {
mavenPreferencePage.setUpdateMavenProjectsOnStartup(false);

assertFalse(mavenPreferencePage.isDebugOutputChecked());
// assertFalse(mavenPreferencePage.isDoNotAutoUpdateDepsChecked()); # is not a part of 2023-09 Eclipse
assertFalse(mavenPreferencePage.isDoNotAutoUpdateDepsChecked());
assertFalse(mavenPreferencePage.isDownloadArtifactJavadocChecked());
assertFalse(mavenPreferencePage.isDownloadArtifactSourcesChecked());
assertFalse(mavenPreferencePage.isDownloadRepoIndexOnStartupChecked());
Expand Down

0 comments on commit 5427600

Please sign in to comment.