Add additional unit tests to show that singletons can be created in single thread environment and multithread environment. Also add a test to demonstrate a whole with Singleton when instantiating using reflection
Add some logging. Tests pass locally but not on github?
This commit is contained in:
@ -75,6 +75,9 @@ public class LazyLoadedSingletonThreadSafetyTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void test_HoleInSingletonCreationIfUsingReflection() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
public void test_HoleInSingletonCreationIfUsingReflection() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||||
Field[] f = ThreadSafeLazyLoadedIvoryTower.class.getDeclaredFields();
|
Field[] f = ThreadSafeLazyLoadedIvoryTower.class.getDeclaredFields();
|
||||||
|
for (Field ff : f) {
|
||||||
|
System.out.println(ff.getDeclaringClass());
|
||||||
|
}
|
||||||
assertEquals("One field only in ThreadSafeLazyLoadedIvoryTower", 1, f.length);
|
assertEquals("One field only in ThreadSafeLazyLoadedIvoryTower", 1, f.length);
|
||||||
f[0].setAccessible(true);
|
f[0].setAccessible(true);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user