Skip to content

Commit

Permalink
Hide mutable public field (#1412)
Browse files Browse the repository at this point in the history
* handle accounts without access to GCP

* enable/disable deploy button as appropriate

* test

* one more test

* fix one more NullPointerException

* nullToEmpty

* don't expose mutable internal global state
  • Loading branch information
elharo authored Feb 15, 2017
1 parent e432625 commit b2d0e43
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
public class StandardDeployPreferencesTest {

@Rule public final TestProjectCreator projectCreator = new TestProjectCreator();

private final StandardDeployPreferences defaultPreferences = StandardDeployPreferences.getDefaultPreferences();

@Test
public void testDefaultProjectId() {
assertThat(StandardDeployPreferences.DEFAULT.getProjectId(), isEmptyString());
assertThat(defaultPreferences.getProjectId(), isEmptyString());
}

@Test
Expand All @@ -49,22 +50,22 @@ public void testSetProjectId() {

@Test
public void testDefaultVersion() {
assertThat(StandardDeployPreferences.DEFAULT.getVersion(), isEmptyString());
assertThat(defaultPreferences.getVersion(), isEmptyString());
}

@Test
public void testDefaultAutoPromote() {
assertTrue(StandardDeployPreferences.DEFAULT.isAutoPromote());
assertTrue(defaultPreferences.isAutoPromote());
}

@Test
public void testDefaultBucket() {
assertThat(StandardDeployPreferences.DEFAULT.getBucket(), isEmptyString());
assertThat(defaultPreferences.getBucket(), isEmptyString());
}

@Test
public void testDefaultStopPreviousVersion() {
assertTrue(StandardDeployPreferences.DEFAULT.isStopPreviousVersion());
assertTrue(defaultPreferences.isStopPreviousVersion());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ private void applyPreferences(StandardDeployPreferences preferences) {
setBucket(preferences.getBucket());
}

public void resetToDefaults() {
applyPreferences(StandardDeployPreferences.DEFAULT);
void resetToDefaults() {
applyPreferences(StandardDeployPreferences.getDefaultPreferences());
}

public void savePreferences() throws BackingStoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class StandardDeployPreferences {

public static final String PREFERENCE_STORE_QUALIFIER =
"com.google.cloud.tools.eclipse.appengine.deploy";
"com.google.cloud.tools.eclipse.appengine.deploy";

static final String PREF_ACCOUNT_EMAIL = "account.email";
static final String PREF_PROJECT_ID = "project.id";
Expand All @@ -37,11 +37,9 @@ public class StandardDeployPreferences {
static final String PREF_STOP_PREVIOUS_VERSION = "project.previousVersion.stop";

private IEclipsePreferences preferenceStore;
// todo since this is mutable it shouldn;t be in all caps
public static final StandardDeployPreferences DEFAULT;

static {
DEFAULT = new StandardDeployPreferences(DeployPreferenceInitializer.getDefaultPreferences());
public static StandardDeployPreferences getDefaultPreferences() {
return new StandardDeployPreferences(DeployPreferenceInitializer.getDefaultPreferences());
}

public StandardDeployPreferences(IProject project) {
Expand Down

0 comments on commit b2d0e43

Please sign in to comment.