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
@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); request.getBuildProperties().getMaven().put("ignore.property", () -> "yes");
generateGradleBuild(request).contains("name = 'test'") 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"); .doesNotContain("ignore.property");
} }
@@ -63,13 +63,20 @@ public class GradleBuildAssert {
return contains("maven { url \"" + url + "\" }"); return contains("maven { url \"" + url + "\" }");
} }
public GradleBuildAssert hasBuildProperties(String... pairs) { /**
StringBuilder builder = new StringBuilder("ext {\n"); * Assert the build contains only the specified properties
for (String pair : pairs) { * @param values the property value pairs
int index = pair.indexOf('='); * @return this for method chaining.
String name = (index > 0) ? pair.substring(0, index) : pair; */
String value = (index > 0) ? pair.substring(index + 1) : ""; public GradleBuildAssert hasProperties(String... values) {
builder.append("\tset('" + name + "', '" + value + "')\n"); 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("}"); builder.append("}");
return contains(builder.toString()); return contains(builder.toString());