Allow passing overwrite behavior through the GemInstaller

This commit is contained in:
R. Tyler Croy 2015-08-21 18:32:52 -07:00
parent 7f5fc8f92a
commit 172557e0be
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
3 changed files with 75 additions and 2 deletions

View File

@ -39,7 +39,7 @@ dependencies {
/* Used for FileUtils and deleting integration test dirs */
testCompile 'org.apache.commons:commons-io:1.3.2'
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
testCompile 'org.apache.commons:commons-io:1.3.2+'
testCompile 'cglib:cglib-nodep:3.1'
}
test {

View File

@ -14,22 +14,64 @@ public class GemInstaller {
FAIL
};
protected com.github.jrubygradle.jem.internal.GemInstaller impl;
/**
* Create an installer with the given installation directory and a single gem
*
* @param installDir
* @param gemPath
*/
public GemInstaller(String installDir, String gemPath) {
this(installDir, new File(gemPath));
}
/**
* Create an installer with the given installation directory and a single gem
*
* @param installDir
* @param gemFile
*/
public GemInstaller(String installDir, File gemFile) {
this(installDir, Arrays.asList(gemFile));
}
/**
* Create an installer with the given installation directory and a list of gems
*
* @param installDir
* @param gemPaths
*/
public GemInstaller(String installDir, List<File> gemPaths) {
impl = new com.github.jrubygradle.jem.internal.GemInstaller(installDir, gemPaths);
}
/**
* Inject a custom GemInstaller implementation that adheres to the private internal API.
*
* Chances are you do not want this constructor, which is largely used for unit testing!
*
* @param implementation
*/
public GemInstaller(com.github.jrubygradle.jem.internal.GemInstaller implementation) {
impl = implementation;
}
/**
* Install the gems in the configured installation directory with all
* the default settings
*/
public void install() {
impl.install();
}
/**
* Install the gems in the configuration installation directory with the given
* overwrite setting
*
* @param overwriteBehavior
*/
public void install(DuplicateBehavior overwriteBehavior) {
impl.install(overwriteBehavior);
}
}

View File

@ -4,7 +4,10 @@ import spock.lang.*
import java.nio.file.Files
import java.nio.file.Path
import com.github.jrubygradle.jem.internal.GemInstaller as GemInstallerImpl
/**
* Test the externally facing GemInstaller API
*/
class GemInstallerSpec extends Specification {
final String FIXTURES_ROOT = new File(['src', 'test', 'resources'].join(File.separator)).absolutePath
@ -14,6 +17,13 @@ class GemInstallerSpec extends Specification {
Path installDirPath = Files.createTempDirectory("geminstallerspec")
String installDir = installDirPath as String
GemInstallerImpl mockedImpl() {
return Mock(GemInstallerImpl, constructorArgs: [
installDir,
[GEM_FIXTURE]
])
}
def "ctor should take a dir and single path"() {
when:
installer = new GemInstaller(installDir, GEM_FIXTURE)
@ -45,4 +55,25 @@ class GemInstallerSpec extends Specification {
then:
installer instanceof GemInstaller
}
def "install() should call our impl with defaults"() {
given:
GemInstallerImpl impl = mockedImpl()
GemInstaller installer = new GemInstaller(impl)
1 * impl.install()
expect:
installer.install()
}
def "install(DuplicateBehavior) should pass those attributes on to impl"() {
given:
GemInstaller.DuplicateBehavior behavior = GemInstaller.DuplicateBehavior.OVERWRITE
GemInstallerImpl impl = mockedImpl()
GemInstaller installer = new GemInstaller(impl)
1 * impl.install(behavior)
expect:
installer.install(behavior)
}
}