Fixed invalid parsing of ids

without this change when someone has provided an empty value of port then a default classifier was set instead of picking the provided one

fixes #176
This commit is contained in:
Marcin Grzejszczak
2016-12-22 19:10:42 +01:00
parent 1fe79521ac
commit 4582a6a3bf
3 changed files with 16 additions and 3 deletions

View File

@@ -76,7 +76,7 @@ public class StubConfiguration {
stubsGroupId = splitPath[0];
stubsArtifactId = splitPath[1];
stubsVersion = splitPath.length >= 3 ? splitPath[2] : DEFAULT_VERSION;
stubsClassifier = splitPath.length == 4 ? splitPath[3] : defaultClassifier;
stubsClassifier = splitPath.length >= 4 ? splitPath[3] : defaultClassifier;
}
return new String[] { stubsGroupId, stubsArtifactId, stubsVersion,
stubsClassifier };

View File

@@ -102,8 +102,7 @@ public class StubsParser {
try {
port = Integer.valueOf(splitEntry[splitEntry.length-1]);
id = id.substring(0, id.lastIndexOf(":"));
} catch (NumberFormatException e) {
}
} catch (NumberFormatException e) {}
return new StubSpecification(new StubConfiguration(id, defaultClassifier), port);
}

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.contract.stubrunner
import spock.lang.Issue
import spock.lang.Specification
class StubRunnerOptionsBuilderSpec extends Specification {
@@ -81,4 +82,17 @@ class StubRunnerOptionsBuilderSpec extends Specification {
then:
options.getDependencies().toString() == '[foo:bar:+:xxx]'
}
@Issue("#176")
def shouldCreateDependenciesWithEmptyPort() {
given:
builder.withStubs('groupId:artifactId:version:classifier:')
when:
StubRunnerOptions options = builder.build()
then:
options.getDependencies().toString() == '[groupId:artifactId:version:classifier]'
}
}