/*
 * Copyright 2019 DiffPlug
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.diffplug.gradle;

import java.io.IOException;
import java.io.Writer;

import org.junit.Assert;
import org.junit.Test;

import com.diffplug.common.base.StringPrinter;

public class GoomphCacheLocationInitFromProjectTest extends GradleIntegrationTest {
	@Test
	public void ensureOverrideWorks() throws IOException {
		write("build.gradle",
				"plugins {",
				"    id 'com.diffplug.gradle.oomph.ide'",
				"}",
				"ext.goomph_override_p2bootstrapUrl='somewhere'",
				"com.diffplug.gradle.GoomphCacheLocations.initFromProject(project)",
				"System.out.println(com.diffplug.gradle.GoomphCacheLocations.p2bootstrapUrl())",
				// if we leave it, it will muck with future testkit tests
				"project.afterEvaluate { com.diffplug.gradle.GoomphCacheLocations.override_p2bootstrapUrl=null }");
		StringBuilder buffer = new StringBuilder();
		StringPrinter printer = new StringPrinter(buffer::append);
		try (Writer writer = printer.toPrintWriter()) {
			gradleRunner().forwardStdOutput(writer).build();
		}
		String firstLine = buffer.toString().split(System.getProperty("line.separator"))[0];
		Assert.assertEquals("Optional[somewhere]", firstLine);
	}
}

@@ -648,55 +648,47 @@
 on;%0A
+%0A
 import 
-java.io.Writer;%0A%0Aimport org.junit
+org.assertj.core.api
 .Assert
+ions
 ;%0Aim
@@ -700,66 +700,64 @@
 org.
-junit.Tes
+gradle.testkit.runner.BuildResul
 t;%0A
-%0A
 import 
-com.diffplug.common.base.StringPrinter
+org.junit.Test
 ;%0A%0Ap
@@ -1149,16 +1149,75 @@
 println(
+%5C%22test%5C%22);%22,%0A%09%09%09%09%22System.out.println(%5C%22p2bootstrapUrl=%5C%22 + 
 com.diff
@@ -1441,329 +1441,120 @@
 ;%0A%09%09
-StringBuilder buffer = new StringBuilder();%0A%09%09StringPrinter printer = new StringPrinter(buffer::append);%0A%09%09try (Writer writer = printer.toPrintWriter()) %7B%0A%09%09%09gradleRunner().forwardStdOutput(writer).build();%0A%09%09%7D%0A%09%09String firstLine = buffer.toString().split(System.getProperty(%22line.separator%22))%5B0%5D;%0A%09%09Assert.assertEquals(%22
+BuildResult build = gradleRunner().build();%0A%09%09Assertions.assertThat(build.getOutput()).contains(%22p2bootstrapUrl=
 Opti
@@ -1573,19 +1573,8 @@
 re%5D%22
-, firstLine
 );%0A%09

Fix GoomphCacheLocationInitFromProjectTest for new gradle.