File tree Expand file tree Collapse file tree
singleton/src/test/java/com/iluwatar/singleton Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626
2727import static org .junit .jupiter .api .Assertions .assertThrows ;
2828
29+ import static org .junit .jupiter .api .Assertions .assertSame ;
30+
2931import org .junit .jupiter .api .Test ;
3032
3133/** EnumIvoryTowerTest */
@@ -43,5 +45,13 @@ void testCreatingNewInstanceByReflection() throws Exception {
4345 // Java does not allow Enum instantiation
4446 // http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.9
4547 assertThrows (ReflectiveOperationException .class , EnumIvoryTower .class ::getDeclaredConstructor );
48+
49+
50+ }
51+ @ Test
52+ void testEnumSingletonIdentity () {
53+ var instance1 = EnumIvoryTower .INSTANCE ;
54+ var instance2 = EnumIvoryTower .INSTANCE ;
55+ assertSame (instance1 , instance2 , "Enum singleton instances should be identical" );
4656 }
4757}
You can’t perform that action at this time.
0 commit comments