mirror of
https://github.com/apache/struts.git
synced 2026-08-06 23:27:07 +00:00
Update:
- Added arbitrary code coverage test.
This commit is contained in:
@@ -104,4 +104,60 @@ public class StrutsJavaConfigurationProviderTest {
|
||||
Assert.assertTrue(names.contains("struts"));
|
||||
Assert.assertTrue(names.contains("struts.test.bean"));
|
||||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* This test is purely to provide code coverage for {@link AbstractBeanSelectionProvider}.
|
||||
* It uses an arbitrary setup to ensure a code path not followed in the registration test
|
||||
* is traversed.
|
||||
*/
|
||||
public void testAbstractBeanProviderCoverage() throws Exception {
|
||||
final ConstantConfig constantConfig = new ConstantConfig();
|
||||
final String expectedUnknownHandler = "expectedUnknownHandler";
|
||||
|
||||
StrutsJavaConfiguration javaConfig = new StrutsJavaConfiguration() {
|
||||
@Override
|
||||
public List<String> unknownHandlerStack() {
|
||||
return Collections.singletonList(expectedUnknownHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConstantConfig> constants() {
|
||||
return Collections.singletonList(constantConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BeanConfig> beans() {
|
||||
return Arrays.asList(
|
||||
new BeanConfig(TestBean.class, "struts")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<BeanSelectionConfig> beanSelection() {
|
||||
return Optional.of(new BeanSelectionConfig(TestBeanSelectionProvider.class, "testBeans"));
|
||||
}
|
||||
};
|
||||
|
||||
StrutsJavaConfigurationProvider provider = new StrutsJavaConfigurationProvider(javaConfig);
|
||||
Configuration configuration = new MockConfiguration();
|
||||
ContainerBuilder builder = new ContainerBuilder();
|
||||
LocatableProperties props = new LocatableProperties();
|
||||
|
||||
provider.init(configuration);
|
||||
provider.register(builder, props);
|
||||
|
||||
props.put(CodeCoverageTestClass1.ALIAS_KEY, CodeCoverageTestClass1.ALIAS_VALUE);
|
||||
TestBeanSelectionProvider testBeanSelectionProvider = new TestBeanSelectionProvider();
|
||||
testBeanSelectionProvider.aliasCallCoverage(CodeCoverageTestClass1.class, builder, props, CodeCoverageTestClass1.ALIAS_KEY, Scope.THREAD);
|
||||
}
|
||||
|
||||
final class CodeCoverageTestClass1 extends Object {
|
||||
public static final String ALIAS_KEY = "testAliasKey";
|
||||
public static final String ALIAS_VALUE = "testAliasValue";
|
||||
|
||||
public CodeCoverageTestClass1() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.apache.struts2.config;
|
||||
import com.opensymphony.xwork2.TestBean;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.inject.ContainerBuilder;
|
||||
import com.opensymphony.xwork2.inject.Scope;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
|
||||
public class TestBeanSelectionProvider extends AbstractBeanSelectionProvider {
|
||||
@@ -30,4 +31,9 @@ public class TestBeanSelectionProvider extends AbstractBeanSelectionProvider {
|
||||
alias(TestBean.class, "struts.test.bean", builder, props);
|
||||
}
|
||||
|
||||
public void aliasCallCoverage(Class aliasClass, ContainerBuilder builder, LocatableProperties props, String aliasKey, Scope scope) throws ConfigurationException {
|
||||
// Allow for coverage testing of AbstractBeanSelectionProvider.
|
||||
alias(aliasClass, aliasKey, builder, props, scope);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user