-
Notifications
You must be signed in to change notification settings - Fork 18
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
Showing
4 changed files
with
206 additions
and
23 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
19 changes: 19 additions & 0 deletions
19
src/main/groovy/nebula/test/gradle/GradleVersionComparator.groovy
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,19 @@ | ||
package nebula.test.gradle | ||
|
||
import org.gradle.util.GradleVersion | ||
|
||
@Category(String) | ||
class GradleVersionComparator { | ||
|
||
boolean versionGreaterThan(String version) { | ||
return versionCompareTo(this, version) > 0 | ||
} | ||
|
||
boolean versionLessThan(String version) { | ||
return versionCompareTo(this, version) < 0 | ||
} | ||
|
||
int versionCompareTo(String v1, String v2) { | ||
return GradleVersion.version(v1).compareTo(GradleVersion.version(v2)) | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/test/groovy/nebula/test/gradle/GradleVersionComparatorSpec.groovy
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,36 @@ | ||
package nebula.test.gradle | ||
|
||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
@Subject(GradleVersionComparator) | ||
class GradleVersionComparatorSpec extends Specification { | ||
|
||
def 'checks if version is greater than'() { | ||
given: | ||
String version = '5.0' | ||
Boolean result | ||
|
||
when: | ||
use(GradleVersionComparator) { | ||
result = version.versionGreaterThan('4.10.3') | ||
} | ||
|
||
then: | ||
result | ||
} | ||
|
||
def 'checks if version is less than'() { | ||
given: | ||
String version = '5.0' | ||
Boolean result | ||
|
||
when: | ||
use(GradleVersionComparator) { | ||
result = version.versionLessThan('5.1') | ||
} | ||
|
||
then: | ||
result | ||
} | ||
} |