[SPR-8387] Fleshing out the implementation of processContextConfiguration() in DelegatingSmartContextLoader.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -53,9 +53,13 @@ public class TestContextManagerTests {
|
||||
|
||||
protected static final Log logger = LogFactory.getLog(TestContextManagerTests.class);
|
||||
|
||||
private TestContextManager testContextManager = null;
|
||||
private final TestContextManager testContextManager = new TestContextManager(ExampleTestCase.class);
|
||||
|
||||
|
||||
private Method getTestMethod() throws NoSuchMethodException {
|
||||
return ExampleTestCase.class.getDeclaredMethod("exampleTestMethod", (Class<?>[]) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the <em>execution order</em> of 'before' and 'after' test method
|
||||
* calls on {@link TestExecutionListener listeners} registered for the
|
||||
@@ -108,16 +112,10 @@ public class TestContextManagerTests {
|
||||
|
||||
@Before
|
||||
public void setUpTestContextManager() throws Throwable {
|
||||
|
||||
final Method testMethod = ExampleTestCase.class.getDeclaredMethod("exampleTestMethod", (Class<?>[]) null);
|
||||
this.testContextManager = new TestContextManager(ExampleTestCase.class);
|
||||
this.testContextManager.registerTestExecutionListeners(new NamedTestExecutionListener(FIRST),
|
||||
new NamedTestExecutionListener(SECOND), new NamedTestExecutionListener(THIRD));
|
||||
|
||||
assertEquals("Verifying the number of registered TestExecutionListeners.", 6,
|
||||
assertEquals("Verifying the number of registered TestExecutionListeners.", 3,
|
||||
this.testContextManager.getTestExecutionListeners().size());
|
||||
|
||||
this.testContextManager.beforeTestMethod(new ExampleTestCase(), testMethod);
|
||||
this.testContextManager.beforeTestMethod(new ExampleTestCase(), getTestMethod());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,13 +131,11 @@ public class TestContextManagerTests {
|
||||
|
||||
@After
|
||||
public void tearDownTestContextManager() throws Throwable {
|
||||
final Method testMethod = ExampleTestCase.class.getDeclaredMethod("exampleTestMethod", (Class<?>[]) null);
|
||||
this.testContextManager.afterTestMethod(new ExampleTestCase(), testMethod, null);
|
||||
this.testContextManager = null;
|
||||
this.testContextManager.afterTestMethod(new ExampleTestCase(), getTestMethod(), null);
|
||||
}
|
||||
|
||||
|
||||
@ContextConfiguration
|
||||
@TestExecutionListeners({ FirstTel.class, SecondTel.class, ThirdTel.class })
|
||||
private static class ExampleTestCase {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -158,13 +154,13 @@ public class TestContextManagerTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTestMethod(final TestContext testContext) {
|
||||
afterTestMethodCalls.add(this.name);
|
||||
public void beforeTestMethod(final TestContext testContext) {
|
||||
beforeTestMethodCalls.add(this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTestMethod(final TestContext testContext) {
|
||||
beforeTestMethodCalls.add(this.name);
|
||||
public void afterTestMethod(final TestContext testContext) {
|
||||
afterTestMethodCalls.add(this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -173,4 +169,25 @@ public class TestContextManagerTests {
|
||||
}
|
||||
}
|
||||
|
||||
private static class FirstTel extends NamedTestExecutionListener {
|
||||
|
||||
public FirstTel() {
|
||||
super(FIRST);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SecondTel extends NamedTestExecutionListener {
|
||||
|
||||
public SecondTel() {
|
||||
super(SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ThirdTel extends NamedTestExecutionListener {
|
||||
|
||||
public ThirdTel() {
|
||||
super(THIRD);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.springframework.test.context.MergedContextConfiguration;
|
||||
*/
|
||||
public class DelegatingSmartContextLoaderTests {
|
||||
|
||||
private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];
|
||||
|
||||
private final DelegatingSmartContextLoader loader = new DelegatingSmartContextLoader();
|
||||
|
||||
@@ -48,6 +48,12 @@ public class DelegatingSmartContextLoaderTests {
|
||||
// TODO test processContextConfiguration().
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void doesNotSupportNullConfig() {
|
||||
MergedContextConfiguration mergedConfig = null;
|
||||
loader.supports(mergedConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotSupportEmptyConfig() {
|
||||
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
|
||||
@@ -76,6 +82,19 @@ public class DelegatingSmartContextLoaderTests {
|
||||
assertTrue(loader.supports(mergedConfig));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void loadContextWithNullConfig() throws Exception {
|
||||
MergedContextConfiguration mergedConfig = null;
|
||||
loader.loadContext(mergedConfig);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void loadContextWithoutLocationsAndConfigurationClasses() throws Exception {
|
||||
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
|
||||
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
loader.loadContext(mergedConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadContext() {
|
||||
// TODO test loadContext().
|
||||
|
||||
Reference in New Issue
Block a user