Skip to content

Commit 54d96a8

Browse files
author
Zachary Thompson
committed
Add identity test for EnumIvoryTower single
1 parent 2d39fe7 commit 54d96a8

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

singleton/src/test/java/com/iluwatar/singleton/EnumIvoryTowerTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import static org.junit.jupiter.api.Assertions.assertThrows;
2828

29+
import static org.junit.jupiter.api.Assertions.assertSame;
30+
2931
import 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
}

0 commit comments

Comments
 (0)