Skip to content

Accessing static fields

stephanenicolas edited this page Sep 13, 2013 · 1 revision

BoundBox provides access to all static fields defined in a given class and its super classes.


Let's say we have a class A like :

@SuppressWarnings("unused")
public class A {
 private static String foo = "bb";
}

With BoundBox, you can write a test that accesses static fields of A :

@BoundBox( boundClass = A.class )
public class ATest {
 
 @Test
 public void testStaticFieldRead() {
   //GIVEN
   //WHEN
   //THEN
   assertEquals( "bb", BoundBoxOfA.boundBox_getFoo());
 }

 @Test
 public void testStaticFieldWrite() {
   //GIVEN
   //WHEN
   BoundBoxOfA.boundBox_setFoo("cc");
   //THEN
   assertEquals( "cc", BoundBoxOfA.boundBox_getFoo());
 }
}

For all static fields defined in a class A, its BoundBox will contain static setters and getters prefixed with boundBox_. This allows to avoid collisions with the setters and getters defined in A itself.