Skip to content

Commit

Permalink
Set correct validation result when switching SDK management option (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chanseokoh authored and briandealwis committed Feb 7, 2018
1 parent 243befb commit 2425972
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ Bundle-Version: 0.1.0.qualifier
Fragment-Host: com.google.cloud.tools.eclipse.sdk.ui
Require-Bundle: com.google.cloud.tools.eclipse.test.dependencies
Import-Package: com.google.cloud.tools.eclipse.test.util,
com.google.cloud.tools.eclipse.test.util.ui
com.google.cloud.tools.eclipse.test.util.ui,
org.eclipse.swtbot.swt.finder.widgets
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@
import com.google.cloud.tools.eclipse.test.util.ui.ShellTestResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -76,8 +80,7 @@ public void testNonExistentPath() {

@Test
public void testInvalidPath() {
when(preferences.getString(CloudSdkPreferences.CLOUD_SDK_PATH))
.thenReturn(tempFolder.getRoot().getAbsolutePath());
when(preferences.getString(CloudSdkPreferences.CLOUD_SDK_PATH)).thenReturn(tempFolder.getRoot().getAbsolutePath());
createPreferenceArea();
assertEquals(IStatus.WARNING, area.getStatus().getSeverity());

Expand Down Expand Up @@ -153,4 +156,21 @@ public void testPerformApply_preferencesSaved() {

verify(preferences).putValue(CloudSdkPreferences.CLOUD_SDK_MANAGEMENT, "MANUAL");
}

@Test
public void testValidationStatus_switchManagementOption() {
CloudSdkManager.forceManagedSdkFeature = true;
when(preferences.getString(CloudSdkPreferences.CLOUD_SDK_MANAGEMENT)).thenReturn("MANUAL");
when(preferences.getString(CloudSdkPreferences.CLOUD_SDK_PATH)).thenReturn("/non-existing/directory");
createPreferenceArea();

assertTrue(useLocalSdk.getSelection());
assertEquals(IStatus.ERROR, area.getStatus().getSeverity());

new SWTBotCheckBox(useLocalSdk).click();
assertTrue(area.getStatus().isOK());

new SWTBotCheckBox(useLocalSdk).click();
assertEquals(IStatus.ERROR, area.getStatus().getSeverity());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
Expand Down Expand Up @@ -93,6 +94,13 @@ public void widgetSelected(SelectionEvent event) {
useLocalSdk.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (!useLocalSdk.getSelection()) {
status = Status.OK_STATUS;
} else {
sdkLocation.doCheckState();
}
fireValueChanged(VALUE, "", "");

updateControlEnablement();
}
});
Expand Down

0 comments on commit 2425972

Please sign in to comment.