From: Juergen H. <jho...@us...> - 2008-10-30 17:00:29
|
Update of /cvsroot/springframework/spring/tiger/mock/org/springframework/test/context In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv19955/tiger/mock/org/springframework/test/context Modified Files: TestContext.java Log Message: TestContext accesses internal fields directly Index: TestContext.java =================================================================== RCS file: /cvsroot/springframework/spring/tiger/mock/org/springframework/test/context/TestContext.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** TestContext.java 31 Mar 2008 07:15:40 -0000 1.27 --- TestContext.java 30 Oct 2008 17:00:24 -0000 1.28 *************** *** 35,40 **** /** ! * TestContext encapsulates the context in which a test is executed, agnostic of ! * the actual testing framework in use. * * @author Sam Brannen --- 35,40 ---- /** ! * TestContext encapsulates the context in which a test is executed, ! * agnostic of the actual testing framework in use. * * @author Sam Brannen *************** *** 44,53 **** public class TestContext extends AttributeAccessorSupport { - private static final String DEFAULT_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.support.GenericXmlContextLoader"; - private static final long serialVersionUID = -5827157174866681233L; private static final Log logger = LogFactory.getLog(TestContext.class); private final ContextCache contextCache; --- 44,55 ---- public class TestContext extends AttributeAccessorSupport { private static final long serialVersionUID = -5827157174866681233L; + private static final String DEFAULT_CONTEXT_LOADER_CLASS_NAME = + "org.springframework.test.context.support.GenericXmlContextLoader"; + private static final Log logger = LogFactory.getLog(TestContext.class); + private final ContextCache contextCache; *************** *** 118,123 **** * Retrieve {@link ApplicationContext} resource locations for the supplied * {@link Class class}, using the supplied {@link ContextLoader} to ! * {@link ContextLoader#processLocations(Class, String...) process} the ! * locations. * <p>Note that the * {@link ContextConfiguration#inheritLocations() inheritLocations} flag of --- 120,124 ---- * Retrieve {@link ApplicationContext} resource locations for the supplied * {@link Class class}, using the supplied {@link ContextLoader} to ! * {@link ContextLoader#processLocations(Class, String...) process} the locations. * <p>Note that the * {@link ContextConfiguration#inheritLocations() inheritLocations} flag of *************** *** 161,175 **** /** ! * Build an {@link ApplicationContext} for this test context using the ! * configured {@link #getContextLoader() ContextLoader} and ! * {@link #getLocations() resource locations}. * @throws Exception if an error occurs while building the application context */ private ApplicationContext loadApplicationContext() throws Exception { ! Assert.notNull(getContextLoader(), ! "Can not build an ApplicationContext with a NULL 'contextLoader'. Consider annotating your test class with @ContextConfiguration."); ! Assert.notNull(getLocations(), ! "Can not build an ApplicationContext with a NULL 'locations' array. Consider annotating your test class with @ContextConfiguration."); ! return getContextLoader().loadContext(getLocations()); } --- 162,175 ---- /** ! * Build an ApplicationContext for this test context using the ! * configured ContextLoader and resource locations. * @throws Exception if an error occurs while building the application context */ private ApplicationContext loadApplicationContext() throws Exception { ! Assert.notNull(this.contextLoader, "Can not build an ApplicationContext with a NULL 'contextLoader'. " + ! "Consider annotating your test class with @ContextConfiguration."); ! Assert.notNull(this.locations, "Can not build an ApplicationContext with a NULL 'locations' array. " + ! "Consider annotating your test class with @ContextConfiguration."); ! return this.contextLoader.loadContext(this.locations); } *************** *** 177,181 **** * Convert the supplied context <code>key</code> to a String * representation for use in caching, logging, etc. - * @param key the context key to convert to a String */ private String contextKeyString(Serializable key) { --- 177,180 ---- *************** *** 192,202 **** public ApplicationContext getApplicationContext() { ApplicationContext context = null; ! ContextCache cache = getContextCache(); ! synchronized (cache) { ! context = cache.get(contextKeyString(getLocations())); if (context == null) { try { context = loadApplicationContext(); ! cache.put(contextKeyString(getLocations()), context); } catch (Exception ex) { --- 191,200 ---- public ApplicationContext getApplicationContext() { ApplicationContext context = null; ! synchronized (this.contextCache) { ! context = this.contextCache.get(contextKeyString(this.locations)); if (context == null) { try { context = loadApplicationContext(); ! this.contextCache.put(contextKeyString(this.locations), context); } catch (Exception ex) { *************** *** 209,241 **** /** - * Get the {@link ContextCache context cache} for this test context. - * @return the context cache (never <code>null</code>) - */ - ContextCache getContextCache() { - return this.contextCache; - } - - /** - * Get the {@link ContextLoader} to use for loading the - * {@link ApplicationContext} for this test context. - * @return the context loader. May be <code>null</code> if the current - * test context is not configured to use an application context. - */ - ContextLoader getContextLoader() { - return this.contextLoader; - } - - /** - * Get the resource locations to use for loading the - * {@link ApplicationContext} for this test context. - * @return the application context resource locations. - * May be <code>null</code> if the current test context is - * not configured to use an application context. - */ - String[] getLocations() { - return this.locations; - } - - /** * Get the {@link Class test class} for this test context. * @return the test class (never <code>null</code>) --- 207,210 ---- *************** *** 246,250 **** /** ! * Gets the current {@link Object test instance} for this test context. * <p>Note: this is a mutable property. * @return the current test instance (may be <code>null</code>) --- 215,219 ---- /** ! * Get the current {@link Object test instance} for this test context. * <p>Note: this is a mutable property. * @return the current test instance (may be <code>null</code>) *************** *** 256,260 **** /** ! * Gets the current {@link Method test method} for this test context. * <p>Note: this is a mutable property. * @return the current test method (may be <code>null</code>) --- 225,229 ---- /** ! * Get the current {@link Method test method} for this test context. * <p>Note: this is a mutable property. * @return the current test method (may be <code>null</code>) *************** *** 266,270 **** /** ! * Gets the {@link Throwable exception} that was thrown during execution of * the {@link #getTestMethod() test method}. * <p>Note: this is a mutable property. --- 235,239 ---- /** ! * Get the {@link Throwable exception} that was thrown during execution of * the {@link #getTestMethod() test method}. * <p>Note: this is a mutable property. *************** *** 284,292 **** */ public void markApplicationContextDirty() { ! getContextCache().setDirty(contextKeyString(getLocations())); } /** ! * Updates this test context to reflect the state of the currently executing test. * @param testInstance the current test instance (may be <code>null</code>) * @param testMethod the current test method (may be <code>null</code>) --- 253,261 ---- */ public void markApplicationContextDirty() { ! this.contextCache.setDirty(contextKeyString(this.locations)); } /** ! * Update this test context to reflect the state of the currently executing test. * @param testInstance the current test instance (may be <code>null</code>) * @param testMethod the current test method (may be <code>null</code>) *************** *** 294,298 **** * or <code>null</code> if no exception was thrown */ ! synchronized void updateState(Object testInstance, Method testMethod, Throwable testException) { this.testInstance = testInstance; this.testMethod = testMethod; --- 263,267 ---- * or <code>null</code> if no exception was thrown */ ! void updateState(Object testInstance, Method testMethod, Throwable testException) { this.testInstance = testInstance; this.testMethod = testMethod; *************** *** 301,317 **** /** ! * Provides a string representation of this test context's ! * {@link #getTestClass() test class}, ! * {@link #getLocations() application context resource locations}, ! * {@link #getTestInstance() test instance}, ! * {@link #getTestMethod() test method}, and ! * {@link #getTestException() test exception}. */ @Override public String toString() { return new ToStringCreator(this). ! append("testClass", getTestClass()). ! append("locations", getLocations()).append("testInstance", getTestInstance()). ! append("testMethod", getTestMethod()).append("testException", getTestException()). toString(); } --- 270,281 ---- /** ! * Provide a String representation of this test context's state. */ @Override public String toString() { return new ToStringCreator(this). ! append("testClass", this.testClass). ! append("locations", this.locations).append("testInstance", this.testInstance). ! append("testMethod", this.testMethod).append("testException", this.testException). toString(); } |