-
Notifications
You must be signed in to change notification settings - Fork 3
/
MementoTest.kt
37 lines (28 loc) · 1.15 KB
/
MementoTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import main.kotlin.CareTaker
import main.kotlin.Originator
import org.junit.Test
class MementoTest {
@Test
fun mementoTest() {
val originator = Originator("initial state")
val careTaker = CareTaker()
careTaker.saveState(originator.createMemento())
println("Current state is ${originator.state}")
originator.state = "State 1"
careTaker.saveState(originator.createMemento())
println("Current state is ${originator.state}")
originator.state = "State 2"
careTaker.saveState(originator.createMemento())
println("Current state is ${originator.state}")
assert(originator.state == "State 2")
originator.restoreMemento(careTaker.restore(1))
println("Current state is ${originator.state}")
assert(originator.state == "State 1")
originator.restoreMemento(careTaker.restore(0))
println("Current state is ${originator.state}")
assert(originator.state == "initial state")
originator.restoreMemento(careTaker.restore(2))
println("Current state is ${originator.state}")
assert(originator.state == "State 2")
}
}