diff --git a/Design Patterns/src/state/atm/with/singleton/tests/ATMMachineTest.java b/Design Patterns/src/state/atm/with/singleton/tests/ATMMachineTest.java new file mode 100644 index 0000000..42795d1 --- /dev/null +++ b/Design Patterns/src/state/atm/with/singleton/tests/ATMMachineTest.java @@ -0,0 +1,43 @@ +package state.atm.with.singleton.tests; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import state.atm.with.singleton.*; + +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertSame; + +class ATMMachineTest { + + private static ATMMachine atmMachine; + + @BeforeAll + static void setup() { + atmMachine = new ATMMachine(); + } + + @Test + void testATMMachineStartsInReadyState() { + assertSame(atmMachine.getAtmState(), NoCard.getInstance(atmMachine)); + } + + @Test + void testATMMachinesStatesAreSingletons() { + ATMState noCard = NoCard.getInstance(atmMachine); + ATMState hasCard = HasCard.getInstance(atmMachine); + ATMState hasPin = HasPin.getInstance(atmMachine); + ATMState noCash = NoCash.getInstance(atmMachine); + + ATMState noCardv2 = NoCard.getInstance(atmMachine); + ATMState hasCardv2 = HasCard.getInstance(atmMachine); + ATMState hasPinv2 = HasPin.getInstance(atmMachine); + ATMState noCashv2 = NoCash.getInstance(atmMachine); + + assertAll("All ATMStates Should Be Singletons", + () -> assertSame(noCard, noCardv2), + () -> assertSame(hasCard, hasCardv2), + () -> assertSame(hasPin, hasPinv2), + () -> assertSame(noCash, noCashv2) + ); + } +} \ No newline at end of file