/*
 * Copyright 2013-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.
 * 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 org.springframework.cloud.consul.config;

import com.ecwid.consul.transport.TransportException;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.context.annotation.Configuration;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author Spencer Gibb
 */
/*
 * @RunWith(SpringRunner.class)
 *
 * @SpringBootTest(classes = ConsulPropertySourceLocatorRetryTests.Config.class,
 * properties = { "spring.application.name=testConsulPropertySourceLocatorRetry",
 * "spring.cloud.consul.host=53210a7c-4809-42cb-8b30-057d2db85fcc",
 * "logging.level.org.springframework.retry=TRACE", "spring.cloud.consul.port=65530",
 * "spring.cloud.consul.retry.maxAttempts=1", "spring.cloud.consul.config.failFast=true"
 * }, webEnvironment = RANDOM_PORT)
 */
public class ConsulPropertySourceLocatorRetryTests {

	@Rule
	public OutputCaptureRule output = new OutputCaptureRule();

	@Test
	public void testRetry() {
		Assert.assertThrows(TransportException.class, () -> {
			new SpringApplicationBuilder(Config.class).properties(
					"spring.application.name=testConsulPropertySourceLocatorRetry",
					"spring.cloud.consul.host=53210a7c-4809-42cb-8b30-057d2db85fcc",
					"logging.level.org.springframework.retry=TRACE", "server.port=0",
					"spring.cloud.consul.port=65530",
					"spring.cloud.consul.retry.maxAttempts=1",
					"spring.cloud.consul.config.failFast=true").run();
		});
		assertThat(output).contains("RetryContext retrieved");
	}

	@Configuration(proxyBeanMethods = false)
	@EnableAutoConfiguration
	static class Config {

	}

}

/*
 * Copyright 2013-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.
 * 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 org.springframework.cloud.consul.config;

import com.ecwid.consul.transport.TransportException;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.context.annotation.Configuration;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author Spencer Gibb
 */
/*
 * @RunWith(SpringRunner.class)
 *
 * @SpringBootTest(classes = ConsulPropertySourceLocatorRetryTests.Config.class,
 * properties = { "spring.application.name=testConsulPropertySourceLocatorRetry",
 * "spring.cloud.consul.host=53210a7c-4809-42cb-8b30-057d2db85fcc",
 * "logging.level.org.springframework.retry=TRACE", "spring.cloud.consul.port=65530",
 * "spring.cloud.consul.retry.maxAttempts=1", "spring.cloud.consul.config.failFast=true"
 * }, webEnvironment = RANDOM_PORT)
 */
public class ConsulPropertySourceLocatorRetryTests {

	@Rule
	public OutputCaptureRule output = new OutputCaptureRule();

	@Test
	public void testRetry() {
		//Assert.assertThrows(TransportException.class, () -> {
		try {
			new SpringApplicationBuilder(Config.class).properties(
					"spring.application.name=testConsulPropertySourceLocatorRetry",
					"spring.cloud.consul.host=53210a7c-4809-42cb-8b30-057d2db85fcc",
					"logging.level.org.springframework.retry=TRACE", "server.port=0",
					"spring.cloud.consul.port=65530",
					"spring.cloud.consul.retry.maxAttempts=1",
					"spring.cloud.consul.config.failFast=true").run();
			Assert.fail("Did not throw TransportException");
		}
		catch (TransportException e) {
			// success
		}
		//});
		assertThat(output).contains("RetryContext retrieved");
	}

	@Configuration(proxyBeanMethods = false)
	@EnableAutoConfiguration
	static class Config {

	}

}

Move to try/catch for test