diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java index 5d4cb08224955b6a9dcea459d689d0754cc311b8..709c82e972ab52e09b695b79fba3ab2d383e5279 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -390,8 +390,10 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot * (i.e., as if we were traversing up the class hierarchy) * @return the resolved {@code ContextLoader} for the supplied {@code testClass} * (never {@code null}) + * @throws IllegalStateException if {@link #getDefaultContextLoaderClass(Class)} + * returns {@code null} */ - private ContextLoader resolveContextLoader(Class testClass, + protected ContextLoader resolveContextLoader(Class testClass, List configAttributesList) { Assert.notNull(testClass, "Class must not be null"); @@ -400,6 +402,9 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot Class contextLoaderClass = resolveExplicitContextLoaderClass(configAttributesList); if (contextLoaderClass == null) { contextLoaderClass = getDefaultContextLoaderClass(testClass); + if (contextLoaderClass == null) { + throw new IllegalStateException("getDefaultContextLoaderClass() must not return null"); + } } if (logger.isTraceEnabled()) { logger.trace(String.format("Using ContextLoader class [%s] for test class [%s]", @@ -428,7 +433,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot * @throws IllegalArgumentException if supplied configuration attributes are * {@code null} or empty */ - private Class resolveExplicitContextLoaderClass( + protected Class resolveExplicitContextLoaderClass( List configAttributesList) { Assert.notEmpty(configAttributesList, "ContextConfigurationAttributes list must not be empty"); @@ -451,12 +456,14 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot } /** - * Determine the default {@link ContextLoader} class to use for the supplied - * test class. + * Determine the default {@link ContextLoader} {@linkplain Class class} + * to use for the supplied test class. *

The class returned by this method will only be used if a {@code ContextLoader} * class has not been explicitly declared via {@link ContextConfiguration#loader}. * @param testClass the test class for which to retrieve the default * {@code ContextLoader} class + * @return the default {@code ContextLoader} class for the supplied test class + * (never {@code null}) */ protected abstract Class getDefaultContextLoaderClass(Class testClass);