-
Notifications
You must be signed in to change notification settings - Fork 19
Limiting hierarchy exposure of a BoundBox
stephanenicolas edited this page Sep 12, 2013
·
2 revisions
When using BoundBox on a class that has several super classes, the BoundBox can become cluttered with too many fields accessors and methods. To prevent this, you can use an optional parameter with the @BoundBox
annotation.
Let's say we have 3 classes A & B & C like :
@SuppressWarnings("unused")
public class A {
private int foo = 2;
}
public class B extends A {
private int bar = 2;
}
public class C extends B {
}
If you specify maxSuperClass = B.class
, then the class BoundBoxOfC
will not contain any thing related to any super class of B. The hierarchy of C
is not explored above B (included).
public class CTest {
@BoundBox( boundClass = C.class, maxSuperClass = B.class )
private BoundBoxOfC boundBoxOfC;
@Before
public void setUp() {
boundBoxOfC = new BoundBoxOfC( new C() );
}
@Test
public void testFieldInB() {
//GIVEN
//WHEN
//THEN
assertEquals( 2, boundBoxOfC.getBar());
}
//there is no method boundBoxOfC.getFoo()
}