From c006b74e910ef20e66fb0f4e7eddd7d97490ffc8 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 15 Apr 2015 00:37:43 +0200 Subject: [PATCH] Make AbsTstCtxBootstrapper.resolveContextLoader protected This commit increases the extensibility of AbstractTestContextBootstrapper by making the resolveContextLoader() and resolveExplicitContextLoaderClass() methods protected instead of private. Furthermore, resolveContextLoader() now throws an IllegalStateException if getDefaultContextLoaderClass() returns null. Issue: SPR-12682 --- .../AbstractTestContextBootstrapper.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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 5d4cb08224..709c82e972 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);