From f663f90424b917277f8276c419774b674588c97a Mon Sep 17 00:00:00 2001 From: Hammy Date: Thu, 17 Dec 2020 20:22:13 +0000 Subject: [PATCH] State Pattern + Singleton Implementation Test --- .../with/singleton/tests/ATMMachineTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Design Patterns/src/state/atm/with/singleton/tests/ATMMachineTest.java 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