private void prepareForAfterCallback(String callbackName, Object testInstance, Method testMethod, @Nullable Throwable exception) { if (logger.isTraceEnabled()) { logger.trace(String.format("%s(): instance [%s], method [%s], exception [%s]", callbackName, testInstance, testMethod, exception)); } getTestContext().updateState(testInstance, testMethod, exception); }
private void prepareForBeforeCallback(String callbackName, Object testInstance, Method testMethod) { if (logger.isTraceEnabled()) { logger.trace(String.format("%s(): instance [%s], method [%s]", callbackName, testInstance, testMethod)); } getTestContext().updateState(testInstance, testMethod, null); }
/** * Get the {@link ApplicationContext} associated with the supplied {@code ExtensionContext}. * @param context the current {@code ExtensionContext} (never {@code null}) * @return the application context * @throws IllegalStateException if an error occurs while retrieving the application context * @see org.springframework.test.context.TestContext#getApplicationContext() */ public static ApplicationContext getApplicationContext(ExtensionContext context) { return getTestContextManager(context).getTestContext().getApplicationContext(); }
logger.trace("prepareTestInstance(): instance [" + testInstance + "]"); getTestContext().updateState(testInstance, null, null); testExecutionListener.prepareTestInstance(getTestContext());
/** * Hook for pre-processing a test class <em>before</em> execution of any * tests within the class. Should be called prior to any framework-specific * <em>before class methods</em> (e.g., methods annotated with JUnit 4's * {@link org.junit.BeforeClass @BeforeClass}). * <p>An attempt will be made to give each registered * {@link TestExecutionListener} a chance to pre-process the test class * execution. If a listener throws an exception, however, the remaining * registered listeners will <strong>not</strong> be called. * @throws Exception if a registered TestExecutionListener throws an * exception * @since 3.0 * @see #getTestExecutionListeners() */ public void beforeTestClass() throws Exception { Class<?> testClass = getTestContext().getTestClass(); if (logger.isTraceEnabled()) { logger.trace("beforeTestClass(): class [" + testClass.getName() + "]"); } getTestContext().updateState(null, null, null); for (TestExecutionListener testExecutionListener : getTestExecutionListeners()) { try { testExecutionListener.beforeTestClass(getTestContext()); } catch (Throwable ex) { logException(ex, "beforeTestClass", testExecutionListener, testClass); ReflectionUtils.rethrowException(ex); } } }
Class<?> testClass = getTestContext().getTestClass(); if (logger.isTraceEnabled()) { logger.trace("afterTestClass(): class [" + testClass.getName() + "]"); getTestContext().updateState(null, null, null); testExecutionListener.afterTestClass(getTestContext());
testExecutionListener.afterTestMethod(getTestContext());
testExecutionListener.afterTestExecution(getTestContext());
testExecutionListener.beforeTestMethod(getTestContext());
testExecutionListener.beforeTestExecution(getTestContext());
@Test public void invokeTestContextManagerFromConcurrentThreads() { TestContextManager tcm = new TestContextManager(TestCase.class); // Run the actual test several times in order to increase the chance of threads // stepping on each others' toes by overwriting the same mutable state in the // TestContext. IntStream.range(1, 20).forEach(i -> { actualMethods.clear(); // Execute TestExecutionListener in parallel, thereby simulating parallel // test method execution. stream(TestCase.class.getDeclaredMethods()).parallel().forEach(testMethod -> { try { tcm.beforeTestClass(); tcm.beforeTestMethod(testInstance, testMethod); // no need to invoke the actual test method tcm.afterTestMethod(testInstance, testMethod, null); tcm.afterTestClass(); } catch (Exception ex) { throw new RuntimeException(ex); } }); assertThat(actualMethods, equalTo(expectedMethods)); }); assertEquals(0, tcm.getTestContext().attributeNames().length); }
private void prepareForAfterCallback(String callbackName, Object testInstance, Method testMethod, @Nullable Throwable exception) { if (logger.isTraceEnabled()) { logger.trace(String.format("%s(): instance [%s], method [%s], exception [%s]", callbackName, testInstance, testMethod, exception)); } getTestContext().updateState(testInstance, testMethod, exception); }
private void prepareForBeforeCallback(String callbackName, Object testInstance, Method testMethod) { if (logger.isTraceEnabled()) { logger.trace(String.format("%s(): instance [%s], method [%s]", callbackName, testInstance, testMethod)); } getTestContext().updateState(testInstance, testMethod, null); }
/** * Get the {@link ApplicationContext} associated with the supplied {@code ExtensionContext}. * @param context the current {@code ExtensionContext} (never {@code null}) * @return the application context * @throws IllegalStateException if an error occurs while retrieving the application context * @see org.springframework.test.context.TestContext#getApplicationContext() */ public static ApplicationContext getApplicationContext(ExtensionContext context) { return getTestContextManager(context).getTestContext().getApplicationContext(); }
/** * Get the {@link ApplicationContext} associated with the supplied {@code ExtensionContext}. * @param context the current {@code ExtensionContext} (never {@code null}) * @return the application context * @throws IllegalStateException if an error occurs while retrieving the application context * @see org.springframework.test.context.TestContext#getApplicationContext() */ public static ApplicationContext getApplicationContext(ExtensionContext context) { return getTestContextManager(context).getTestContext().getApplicationContext(); }
/** * Get the {@link ApplicationContext} associated with the supplied {@code ExtensionContext}. * @param context the current {@code ExtensionContext} (never {@code null}) * @return the application context * @throws IllegalStateException if an error occurs while retrieving the application context * @see org.springframework.test.context.TestContext#getApplicationContext() */ public static ApplicationContext getApplicationContext(ExtensionContext context) { return getTestContextManager(context).getTestContext().getApplicationContext(); }
Class<?> testClass = getTestContext().getTestClass(); if (logger.isTraceEnabled()) { logger.trace("beforeTestClass(): class [" + testClass.getName() + "]"); getTestContext().updateState(null, null, null); testExecutionListener.beforeTestClass(getTestContext());
logger.trace("prepareTestInstance(): instance [" + testInstance + "]"); getTestContext().updateState(testInstance, null, null); testExecutionListener.prepareTestInstance(getTestContext());
logger.trace("prepareTestInstance(): instance [" + testInstance + "]"); getTestContext().updateState(testInstance, null, null); testExecutionListener.prepareTestInstance(getTestContext());
/** * Hook for pre-processing a test class <em>before</em> execution of any * tests within the class. Should be called prior to any framework-specific * <em>before class methods</em> (e.g., methods annotated with JUnit 4's * {@link org.junit.BeforeClass @BeforeClass}). * <p>An attempt will be made to give each registered * {@link TestExecutionListener} a chance to pre-process the test class * execution. If a listener throws an exception, however, the remaining * registered listeners will <strong>not</strong> be called. * @throws Exception if a registered TestExecutionListener throws an * exception * @since 3.0 * @see #getTestExecutionListeners() */ public void beforeTestClass() throws Exception { Class<?> testClass = getTestContext().getTestClass(); if (logger.isTraceEnabled()) { logger.trace("beforeTestClass(): class [" + testClass.getName() + "]"); } getTestContext().updateState(null, null, null); for (TestExecutionListener testExecutionListener : getTestExecutionListeners()) { try { testExecutionListener.beforeTestClass(getTestContext()); } catch (Throwable ex) { logException(ex, "beforeTestClass", testExecutionListener, testClass); ReflectionUtils.rethrowException(ex); } } }