@Nullable private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) { Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); if (annotations.isEmpty()) { return null; } if (annotations.size() == 1) { return annotations.iterator().next().value(); } // Allow directly-present annotation to override annotations that are meta-present. BootstrapWith bootstrapWith = testClass.getDeclaredAnnotation(BootstrapWith.class); if (bootstrapWith != null) { return bootstrapWith.value(); } throw new IllegalStateException(String.format( "Configuration error: found multiple declarations of @BootstrapWith for test class [%s]: %s", testClass.getName(), annotations)); }
@BootstrapWith(FooBootstrapper.class) static class DirectBootstrapWithAnnotationClass {}
private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) { Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); if (annotations.size() < 1) { return null; } if (annotations.size() > 1) { throw new IllegalStateException(String.format( "Configuration error: found multiple declarations of @BootstrapWith for test class [%s]: %s", testClass.getName(), annotations)); } return annotations.iterator().next().value(); }
@BootstrapWith static class EmptyBootstrapWithAnnotationClass {}
private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) { Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); if (annotations.size() < 1) { return null; } if (annotations.size() > 1) { throw new IllegalStateException(String.format( "Configuration error: found multiple declarations of @BootstrapWith for test class [%s]: %s", testClass.getName(), annotations)); } return annotations.iterator().next().value(); }
/** * @author Sam Brannen * @author Phillip Webb * @since 4.3 */ @BootstrapWith(CustomTestContextBootstrapper.class) interface BootstrapWithTestInterface { static class CustomTestContextBootstrapper extends DefaultTestContextBootstrapper { @Override protected List<ContextCustomizerFactory> getContextCustomizerFactories() { return singletonList( (ContextCustomizerFactory) (testClass, configAttributes) -> (ContextCustomizer) (context, mergedConfig) -> context.getBeanFactory().registerSingleton("foo", "foo")); } } }
@Nullable private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) { Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); if (annotations.isEmpty()) { return null; } if (annotations.size() == 1) { return annotations.iterator().next().value(); } // Allow directly-present annotation to override annotations that are meta-present. BootstrapWith bootstrapWith = testClass.getDeclaredAnnotation(BootstrapWith.class); if (bootstrapWith != null) { return bootstrapWith.value(); } throw new IllegalStateException(String.format( "Configuration error: found multiple declarations of @BootstrapWith for test class [%s]: %s", testClass.getName(), annotations)); }
@BootstrapWith(CustomDefaultContextLoaderClassSpringRunnerTests.PropertiesBasedTestContextBootstrapper.class) @ContextConfiguration("PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests-context.properties") public class CustomDefaultContextLoaderClassSpringRunnerTests {
@BootstrapWith(CustomTestContextBootstrapper.class) public class ContextCustomizerSpringRunnerTests {
@BootWithFoo @BootWithBar @BootstrapWith(EnigmaBootstrapper.class) static class LocalDeclarationAndMetaAnnotatedBootstrapWithAnnotationClass {}
@BootstrapWith(FooBootstrapper.class) @Retention(RetentionPolicy.RUNTIME) @interface BootWithFoo {} @BootstrapWith(FooBootstrapper.class) @Retention(RetentionPolicy.RUNTIME) @interface BootWithFooAgain {} @BootstrapWith(BarBootstrapper.class) @Retention(RetentionPolicy.RUNTIME) @interface BootWithBar {}
@ContextConfiguration @WebAppConfiguration @BootstrapWith(CustomWebTestContextBootstrapper.class) public class WebAppConfigurationBootstrapWithTests {