Skip to content

Commit

Permalink
Merge pull request #29 from shipkit/sf
Browse files Browse the repository at this point in the history
Improved exception message
  • Loading branch information
mockitoguy authored Oct 10, 2020
2 parents 0c21abf + 066e68c commit 2b9bd62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/main/java/org/shipkit/auto/version/VersionSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ static boolean isWildcardSpec(String versionSpec) {
return versionSpec.matches("\\d+\\.\\d+\\.\\*");
}

private static String exceptionMessage(File versionFile) {
return "Problems deducting the version automatically. Expected correct 'version' property in file: " + versionFile + "\n" +
"Correct examples: 'version=1.0.*', 'version=2.10.100'";
private static String messageDetails(File versionFile) {
return " 'version' property in file: '" + versionFile.getName() + "'\n" +
" Correct examples: 'version=1.0.*', 'version=2.10.100'";
}

static class MissingVersionKey extends RuntimeException {
MissingVersionKey(File versionFile) {
super(exceptionMessage(versionFile));
super("Missing" + messageDetails(versionFile));
}
}

static class IncorrectVersionFormat extends RuntimeException {
IncorrectVersionFormat(File versionFile, Exception e) {
super(exceptionMessage(versionFile), e);
super("Invalid format of" + messageDetails(versionFile), e);
}
}
}
14 changes: 8 additions & 6 deletions src/test/groovy/org/shipkit/auto/version/VersionSpecTest.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.shipkit.auto.version

import spock.lang.Unroll

import static VersionSpec.readVersionSpec

Expand All @@ -20,28 +21,29 @@ class VersionSpecTest extends TmpFolderSpecification {
e.cause != null
}

def "bad format"() {
def "missing 'version' property"() {
def f = writeFile("noversion=missing")

when:
readVersionSpec(f)

then:
def e = thrown(VersionSpec.MissingVersionKey)
e.message == "Problems deducting the version automatically. Expected correct 'version' property in file: " + f + "\n" +
"Correct examples: 'version=1.0.*', 'version=2.10.100'"
e.message == "Missing 'version' property in file: '" + f.name + "'\n" +
" Correct examples: 'version=1.0.*', 'version=2.10.100'"
}

def "bad version format"() {
@Unroll
def "bad version format: #spec"() {
def f = writeFile("version=" + spec)

when:
readVersionSpec(f)

then:
def e = thrown(VersionSpec.IncorrectVersionFormat)
e.message == "Problems deducting the version automatically. Expected correct 'version' property in file: " + f + "\n" +
"Correct examples: 'version=1.0.*', 'version=2.10.100'"
e.message == "Invalid format of 'version' property in file: '" + f.name + "'\n" +
" Correct examples: 'version=1.0.*', 'version=2.10.100'"
e.cause != null

where:
Expand Down

0 comments on commit 2b9bd62

Please sign in to comment.