Tests that if @EnableDiscoveryClient is used, but there is no implementation on the classpath, then fail

This commit is contained in:
Spencer Gibb
2015-01-19 12:59:48 -07:00
parent 7e0494a0bf
commit 91150c7c83

View File

@@ -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 {
}
}