类org.springframework.boot.test.context.runner.ContextConsumer源码实例Demo

下面列出了怎么用org.springframework.boot.test.context.runner.ContextConsumer的API类实例代码及写法,或者点击链接到github查看源代码。

private ContextConsumer<AssertableApplicationContext> thenCompositeHttpServerSamplerOf(
		SamplerFunction<HttpRequest> instance) {
	return (context) -> {

		SamplerFunction<HttpRequest> serverSampler = context
				.getBean(HttpTracing.class).serverRequestSampler();

		then(serverSampler).isInstanceOf(CompositeHttpSampler.class);

		then(((CompositeHttpSampler) serverSampler).left)
				.isInstanceOf(SkipPatternHttpServerSampler.class);
		then(((CompositeHttpSampler) serverSampler).right).isSameAs(instance);
	};
}
 
源代码2 项目: initializr   文件: ProjectAssetTester.java
/**
 * Configure a {@link ProjectGenerationContext} using the specified
 * {@code description} and use the {@link ContextConsumer} to assert the context.
 * @param description the description of the project to configure
 * @param consumer the consumer of the created {@link ProjectGenerationContext}
 * @see ApplicationContextRunner#run(ContextConsumer)
 */
public void configure(MutableProjectDescription description,
		ContextConsumer<AssertableApplicationContext> consumer) {
	invokeProjectGeneration(description, (contextInitializer) -> {
		new ApplicationContextRunner(ProjectGenerationContext::new).withInitializer((ctx) -> {
			ProjectGenerationContext projectGenerationContext = (ProjectGenerationContext) ctx;
			projectGenerationContext.registerBean(ProjectDescription.class, () -> description);
			contextInitializer.accept(projectGenerationContext);
		}).run(consumer);
		return null;
	});
}
 
private static ContextConsumer<AssertableApplicationContext> assertSpecificHazelcastJetClient(String label) {
    return (context) -> assertThat(context).getBean(JetInstance.class).isInstanceOf(JetInstance.class)
                                           .has(labelEqualTo(label));
}
 
private static ContextConsumer<AssertableApplicationContext> assertSpecificJetServer(String suffix) {
    return context -> {
        JetConfig jetConfig = context.getBean(JetInstance.class).getConfig();
        assertThat(jetConfig.getProperties().getProperty("foo")).isEqualTo("bar-" + suffix);
    };
}
 
private static ContextConsumer<AssertableApplicationContext> assertSpecificJetImdgServer(String clusterName) {
    return context -> {
        JetConfig jetConfig = context.getBean(JetInstance.class).getConfig();
        assertThat(jetConfig.getHazelcastConfig().getClusterName()).isEqualTo(clusterName);
    };
}
 
private ContextConsumer<AssertableApplicationContext> checkNumberOfBeansOfTypeGcpProjectIdProvider(int count) {
	return context -> assertThat(context
			.getBeansOfType(GcpProjectIdProvider.class).size())
					.isEqualTo(count);
}
 
 类所在包
 同包方法