Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40148e6
commit 0a0dd02
Showing
3 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package betamax | ||
|
||
import spock.lang.* | ||
|
||
class RecorderConfigurationSpec extends Specification { | ||
|
||
@Shared String tmpdir = System.properties."java.io.tmpdir" | ||
|
||
def "recorder gets default configuration if not overridden and no properties file exists"() { | ||
given: | ||
def recorder = new Recorder() | ||
|
||
expect: | ||
recorder.tapeRoot == new File("src/test/resources/betamax/tapes") | ||
recorder.proxyPort == 5555 | ||
} | ||
|
||
def "recorder configuration is overridden by map arguments"() { | ||
given: | ||
def recorder = new Recorder(tapeRoot: new File(tmpdir, "tapes"), proxyPort: 1337) | ||
|
||
expect: | ||
recorder.tapeRoot == new File(tmpdir, "tapes") | ||
recorder.proxyPort == 1337 | ||
} | ||
|
||
def "recorder picks up configuration from properties"() { | ||
given: | ||
def properties = new Properties() | ||
properties.setProperty("betamax.tapeRoot", "$tmpdir/tapes") | ||
properties.setProperty("betamax.proxyPort", "1337") | ||
|
||
and: | ||
def recorder = new Recorder(properties) | ||
|
||
expect: | ||
recorder.tapeRoot == new File(tmpdir, "tapes") | ||
recorder.proxyPort == 1337 | ||
} | ||
|
||
def "recorder picks up configuration from properties file"() { | ||
given: | ||
def propertiesFile = new File(tmpdir, "betamax.properties") | ||
def properties = new Properties() | ||
properties.setProperty("betamax.tapeRoot", "$tmpdir/tapes") | ||
properties.setProperty("betamax.proxyPort", "1337") | ||
propertiesFile.withWriter { writer -> | ||
properties.store(writer, null) | ||
} | ||
|
||
and: | ||
Recorder.classLoader.addURL(new File(tmpdir).toURL()) | ||
|
||
and: | ||
def recorder = new Recorder() | ||
|
||
expect: | ||
recorder.tapeRoot == new File(tmpdir, "tapes") | ||
recorder.proxyPort == 1337 | ||
|
||
cleanup: | ||
propertiesFile.delete() | ||
} | ||
|
||
def "constructor arguments take precendence over a properties file"() { | ||
given: | ||
def propertiesFile = new File(tmpdir, "betamax.properties") | ||
def properties = new Properties() | ||
properties.setProperty("betamax.tapeRoot", "$tmpdir/tapes") | ||
properties.setProperty("betamax.proxyPort", "1337") | ||
propertiesFile.withWriter { writer -> | ||
properties.store(writer, null) | ||
} | ||
|
||
and: | ||
Recorder.classLoader.addURL(new File(tmpdir).toURL()) | ||
|
||
and: | ||
def recorder = new Recorder(tapeRoot: new File("test/fixtures/tapes"), proxyPort: 1234) | ||
|
||
expect: | ||
recorder.tapeRoot == new File("test/fixtures/tapes") | ||
recorder.proxyPort == 1234 | ||
|
||
cleanup: | ||
propertiesFile.delete() | ||
} | ||
|
||
} |