From 4582a6a3bfdba643c9175dc8bf90c8a20af9487c Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Thu, 22 Dec 2016 19:10:42 +0100 Subject: [PATCH] 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 --- .../contract/stubrunner/StubConfiguration.java | 2 +- .../contract/stubrunner/util/StubsParser.java | 3 +-- .../stubrunner/StubRunnerOptionsBuilderSpec.groovy | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubConfiguration.java index 2727ea5427..7a35670765 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubConfiguration.java @@ -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 }; diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/util/StubsParser.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/util/StubsParser.java index 8638a0b702..e9381ac2d2 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/util/StubsParser.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/util/StubsParser.java @@ -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); } diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy index c0d4aba44c..14b01bd57a 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilderSpec.groovy @@ -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]' + } }