Cleaned up code and added unit test
@@ -9,12 +9,20 @@ class BintrayDefaultArtifactUrlResolverTest extends Specification {
BintrayDefaultArtifactUrlResolver underTest
Project project = Mock(Project)
+ ExtensionContainer extensionContainer = Mock(ExtensionContainer)
+ BintrayExtension extension = Mock(BintrayExtension)
+ BintrayExtension.PackageConfig pkg = Mock(BintrayExtension.PackageConfig)
- def "concatenates default url correctly"() {
+ def setup() {
+ project.getExtensions() >> extensionContainer
+ extensionContainer.getByType(BintrayExtension.class) >> extension
+ extension.pkg >> pkg
+ }
+
+ def "concatenates default url with userOrg correctly"() {
given:
underTest = new BintrayDefaultArtifactUrlResolver(project, "api", "0.0.1")
project.getGroup() >> "mockito"
- def pkg = mockBintrayPkg()
pkg.userOrg >> "shipkit"
pkg.repo >> "examples"
when:
@@ -23,13 +31,15 @@ class BintrayDefaultArtifactUrlResolverTest extends Specification {
result == "https://bintray.com/shipkit/examples/download_file?file_path=mockito/api/0.0.1/api-0.0.1-sources.jar"
}
- private BintrayExtension.PackageConfig mockBintrayPkg() {
- def extensionContainer = Mock(ExtensionContainer)
- project.getExtensions() >> extensionContainer
- def extension = Mock(BintrayExtension)
- extensionContainer.getByType(BintrayExtension.class) >> extension
- def pkg = Mock(BintrayExtension.PackageConfig)
- extension.pkg >> pkg
- pkg
+ def "concatenates default url with fallback to user correctly"() {
+ given:
+ underTest = new BintrayDefaultArtifactUrlResolver(project, "api", "0.0.1")
+ project.getGroup() >> "mockito"
+ extension.user >> "shipkit"
+ pkg.repo >> "examples"
+ when:
+ def result = underTest.getDefaultUrl("-sources.jar")
+ then:
+ result == "https://bintray.com/shipkit/examples/download_file?file_path=mockito/api/0.0.1/api-0.0.1-sources.jar"
}
}
