For some reason it thinks there are two fields in the CI build. Making this more generic

This commit is contained in:
Richard Jones 2015-10-11 22:16:51 -03:00
parent 31e2940eb1
commit 64e3e1a9e8

View File

@ -4,7 +4,6 @@ import org.junit.Test;
import java.lang.reflect.Field;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@ -20,22 +19,24 @@ public class HolderThreadSafeTest {
HolderThreadSafe hts = new HolderThreadSafe();
{//first call is null
Field[] f = HolderThreadSafe.class.getDeclaredFields();
assertEquals("One field only in HolderThreadSafe", 1, f.length);
f[0].setAccessible(true);
Field[] ff = HolderThreadSafe.class.getDeclaredFields();
for (Field f: ff) {
f.setAccessible(true);
}
assertNull(f[0].get(hts));
assertNull(ff[0].get(hts));
}
// now it is lazily loaded
hts.getHeavy();
{//now it is not null - call via reflection so that the test is the same before and after
Field[] f = HolderThreadSafe.class.getDeclaredFields();
assertEquals("One field only in HolderThreadSafe", 1, f.length);
f[0].setAccessible(true);
Field[] ff = HolderThreadSafe.class.getDeclaredFields();
for (Field f: ff) {
f.setAccessible(true);
}
assertNotNull(f[0].get(hts));
assertNotNull(ff[0].get(hts));
}
}
}