This commit is contained in:
Stephane Nicoll 2019-01-08 09:32:41 +01:00
parent 3ceb608f87
commit b17da2489c
3 changed files with 17 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -718,7 +718,7 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
request.getBuildProperties().getMaven().put("ignore.property", () -> "yes");
generateGradleBuild(request).contains("name = 'test'")
.hasBuildProperties("foo.version=1.2.3", "internalVersion=4.5.6")
.hasProperties("foo.version", "1.2.3", "internalVersion", "4.5.6")
.doesNotContain("ignore.property");
}

View File

@ -63,13 +63,20 @@ public class GradleBuildAssert {
return contains("maven { url \"" + url + "\" }");
}
public GradleBuildAssert hasBuildProperties(String... pairs) {
StringBuilder builder = new StringBuilder("ext {\n");
for (String pair : pairs) {
int index = pair.indexOf('=');
String name = (index > 0) ? pair.substring(0, index) : pair;
String value = (index > 0) ? pair.substring(index + 1) : "";
builder.append("\tset('" + name + "', '" + value + "')\n");
/**
* Assert the build contains only the specified properties
* @param values the property value pairs
* @return this for method chaining.
*/
public GradleBuildAssert hasProperties(String... values) {
StringBuilder builder = new StringBuilder(String.format("ext {%n"));
if (values.length % 2 == 1) {
throw new IllegalArgumentException(
"Size must be even, it is a set of property=value pairs");
}
for (int i = 0; i < values.length; i += 2) {
builder.append(
String.format("\tset('%s', '%s')%n", values[i], values[i + 1]));
}
builder.append("}");
return contains(builder.toString());