From 45b0ac386e1c492e92093552e40b100557dd9d4c Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Sun, 11 Oct 2015 21:54:45 -0300 Subject: [PATCH] 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? --- .../singleton/LazyLoadedSingletonThreadSafetyTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/singleton/src/test/java/com/iluwatar/singleton/LazyLoadedSingletonThreadSafetyTest.java b/singleton/src/test/java/com/iluwatar/singleton/LazyLoadedSingletonThreadSafetyTest.java index 36d04f95f..a19e641f6 100644 --- a/singleton/src/test/java/com/iluwatar/singleton/LazyLoadedSingletonThreadSafetyTest.java +++ b/singleton/src/test/java/com/iluwatar/singleton/LazyLoadedSingletonThreadSafetyTest.java @@ -75,6 +75,9 @@ public class LazyLoadedSingletonThreadSafetyTest { @SuppressWarnings("unchecked") public void test_HoleInSingletonCreationIfUsingReflection() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { Field[] f = ThreadSafeLazyLoadedIvoryTower.class.getDeclaredFields(); + for (Field ff : f) { + System.out.println(ff.getDeclaringClass()); + } assertEquals("One field only in ThreadSafeLazyLoadedIvoryTower", 1, f.length); f[0].setAccessible(true);