diff --git a/src/test/java/org/springframework/cloud/client/discovery/EnableDiscoveryClientMissingImplTests.java b/src/test/java/org/springframework/cloud/client/discovery/EnableDiscoveryClientMissingImplTests.java new file mode 100644 index 00000000..ee023a81 --- /dev/null +++ b/src/test/java/org/springframework/cloud/client/discovery/EnableDiscoveryClientMissingImplTests.java @@ -0,0 +1,38 @@ +package org.springframework.cloud.client.discovery; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.NestedRuntimeException; + +/** + * Tests that if @EnableDiscoveryClient is used, but there is no implementation + * on the classpath, then fail + * @author Spencer Gibb + */ +public class EnableDiscoveryClientMissingImplTests { + + @Test + public void testContextFails() { + try { + new SpringApplicationBuilder() + .sources(App.class) + .web(false) + .run(new String[0]); + } catch (NestedRuntimeException e) { + Throwable rootCause = e.getRootCause(); + assertTrue(rootCause instanceof IllegalStateException); + assertTrue(rootCause.getMessage().contains("no implementations")); + } + } + + @EnableAutoConfiguration + @Configuration + @EnableDiscoveryClient + //this will fail with @EnableDiscoveryClient and no implementation (nothing in spring.factories) + public static class App { + } +}