Simplifies checking of Strict DMI to simple getter

This commit is contained in:
Lukasz Lenart
2015-09-26 08:57:44 +02:00
parent 86afcbe611
commit fdb6daec78
2 changed files with 62 additions and 14 deletions
@@ -600,22 +600,12 @@ public class PackageConfig extends Located implements Comparable, Serializable,
}
public Builder strictMethodInvocation(boolean strict) {
strictDMI = strict;
target.strictMethodInvocation = strict;
return this;
}
public boolean isStrictMethodInvocation() {
// if Strict DMI was disabled in this package,
// return without evaluating parent packages
if (!strictDMI) {
return false;
}
for (PackageConfig parent : target.parents) {
if (parent.isStrictMethodInvocation()) {
return true;
}
}
return true;
return target.strictMethodInvocation;
}
public PackageConfig build() {
@@ -30,5 +30,63 @@ public class PackageConfigTest extends XWorkTestCase {
assertEquals("ref2", cfg.getFullDefaultInterceptorRef());
}
}
public void testStrictDMIInheritance() {
// given
PackageConfig parent = new PackageConfig.Builder("parent").build();
// when
PackageConfig child = new PackageConfig.Builder("child")
.addParent(parent)
.build();
// then
assertTrue(child.isStrictMethodInvocation());
}
public void testStrictDMIInheritanceDisabledInParentPackage() {
// given
PackageConfig parent = new PackageConfig.Builder("parent")
.strictMethodInvocation(false)
.build();
// when
PackageConfig child = new PackageConfig.Builder("child")
.addParent(parent)
.build();
// then
assertTrue(child.isStrictMethodInvocation());
}
public void testStrictDMIInheritanceDisabledInBothPackage() {
// given
PackageConfig parent = new PackageConfig.Builder("parent")
.strictMethodInvocation(false)
.build();
// when
PackageConfig child = new PackageConfig.Builder("child")
.addParent(parent)
.strictMethodInvocation(false)
.build();
// then
assertFalse(child.isStrictMethodInvocation());
}
public void testStrictDMIInheritanceDisabledInChildPackage() {
// given
PackageConfig parent = new PackageConfig.Builder("parent").build();
// when
PackageConfig child = new PackageConfig.Builder("child")
.addParent(parent)
.strictMethodInvocation(false)
.build();
// then
assertFalse(child.isStrictMethodInvocation());
}
}