Skip to content
This repository has been archived by the owner on Mar 25, 2018. It is now read-only.

Commit

Permalink
Enforce the use of builders in Ruby and Chef statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignasi Barrera committed Apr 3, 2013
1 parent 1760b40 commit 89e04c2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public ChefSolo build() {
private RunList runlist;
private final InstallChefGems installChefGems;

public ChefSolo(Optional<String> fileCachePath, Optional<String> rolePath, Optional<String> databagPath,
protected ChefSolo(Optional<String> fileCachePath, Optional<String> rolePath, Optional<String> databagPath,
Optional<ImmutableList<String>> cookbookPath, Optional<String> cookbooksArchiveLocation,
Optional<String> jsonAttributes, Optional<String> group, Optional<Integer> interval,
Optional<String> logLevel, Optional<String> logFile, Optional<String> nodeName, Optional<Integer> splay,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public InstallChefGems build() {

private Optional<String> version;

public InstallChefGems(Optional<String> version) {
protected InstallChefGems(Optional<String> version) {
this.version = version;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@
*/
public class InstallRuby extends StatementList {

public InstallRuby() {
public static Builder builder() {
return new Builder();
}

public static class Builder {
public InstallRuby build() {
return new InstallRuby();
}
}

protected InstallRuby() {
super(call("setupPublicCurl"), call("installRuby"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public InstallRubyGems build() {
private Optional<String> updateSystemVersion;
private boolean updateExistingGems;

public InstallRubyGems(Optional<String> version, boolean updateSystem, Optional<String> updateSystemVersion,
protected InstallRubyGems(Optional<String> version, boolean updateSystem, Optional<String> updateSystemVersion,
boolean updateExistingGems) {
this.version = checkNotNull(version, "version must be set");
this.updateSystem = updateSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@
@Test(groups = "unit", testName = "InstallRubyTest")
public class InstallRubyTest {

@Test(expectedExceptions = UnsupportedOperationException.class,
expectedExceptionsMessageRegExp = "windows not yet implemented")
@Test(expectedExceptions = UnsupportedOperationException.class, expectedExceptionsMessageRegExp = "windows not yet implemented")
public void installRubyInWindows() {
new InstallRuby().render(OsFamily.WINDOWS);
InstallRuby.builder().build().render(OsFamily.WINDOWS);
}

public void installRubyUnix() throws IOException {
assertEquals(new InstallRuby().render(OsFamily.UNIX), Resources.toString(
assertEquals(InstallRuby.builder().build().render(OsFamily.UNIX), Resources.toString(
Resources.getResource("test_install_ruby." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8));
}

public void installRubyUnixInScriptBuilderSourcesSetupPublicCurl() throws IOException {
assertEquals(InitScript.builder().name("install_ruby").run(new InstallRuby()).build().render(OsFamily.UNIX),
assertEquals(
InitScript.builder().name("install_ruby").run(InstallRuby.builder().build()).build().render(OsFamily.UNIX),
Resources.toString(
Resources.getResource("test_install_ruby_scriptbuilder." + ShellToken.SH.to(OsFamily.UNIX)),
Charsets.UTF_8));
Expand Down

0 comments on commit 89e04c2

Please sign in to comment.