|
| 1 | +package ru.nsk.kstatemachine.visitors |
| 2 | + |
| 3 | +import io.kotest.assertions.throwables.shouldThrow |
| 4 | +import io.kotest.core.spec.style.StringSpec |
| 5 | +import io.kotest.matchers.shouldBe |
| 6 | +import ru.nsk.kstatemachine.CoroutineStarterType |
| 7 | +import ru.nsk.kstatemachine.SwitchEvent |
| 8 | +import ru.nsk.kstatemachine.createTestStateMachine |
| 9 | +import ru.nsk.kstatemachine.state.initialState |
| 10 | +import ru.nsk.kstatemachine.state.transition |
| 11 | +import ru.nsk.kstatemachine.statemachine.StateMachine.CreationArguments |
| 12 | + |
| 13 | +class RequireNonBlankNamesVisitorTest : StringSpec({ |
| 14 | + CoroutineStarterType.entries.forEach { coroutineStarterType -> |
| 15 | + "check machine with multiple blank names" { |
| 16 | + val machine = createTestStateMachine(coroutineStarterType) { |
| 17 | + initialState { |
| 18 | + transition<SwitchEvent>() |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + machine.hasBlankNames() shouldBe true |
| 23 | + shouldThrow<IllegalStateException> { |
| 24 | + machine.checkNonBlankNames() |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + "check machine blank name" { |
| 29 | + val machine = createTestStateMachine(coroutineStarterType) { |
| 30 | + initialState("initial") { |
| 31 | + transition<SwitchEvent>("transition") |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + machine.hasBlankNames() shouldBe true |
| 36 | + shouldThrow<IllegalStateException> { |
| 37 | + machine.checkNonBlankNames() |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + "check state blank name" { |
| 42 | + val machine = createTestStateMachine(coroutineStarterType, "machine") { |
| 43 | + initialState { |
| 44 | + transition<SwitchEvent>("transition") |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + machine.hasBlankNames() shouldBe true |
| 49 | + shouldThrow<IllegalStateException> { |
| 50 | + machine.checkNonBlankNames() |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + "check transition blank name" { |
| 55 | + val machine = createTestStateMachine(coroutineStarterType, "machine") { |
| 56 | + initialState("initial") { |
| 57 | + transition<SwitchEvent>() |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + machine.hasBlankNames() shouldBe true |
| 62 | + shouldThrow<IllegalStateException> { |
| 63 | + machine.checkNonBlankNames() |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + "check machine without blank names" { |
| 68 | + val machine = createTestStateMachine(coroutineStarterType, "machine") { |
| 69 | + initialState("initial") { |
| 70 | + transition<SwitchEvent>("transition") |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + machine.hasBlankNames() shouldBe false |
| 75 | + machine.checkNonBlankNames() |
| 76 | + } |
| 77 | + |
| 78 | + "check machine started with blank names and disabled check" { |
| 79 | + createTestStateMachine( |
| 80 | + coroutineStarterType, |
| 81 | + creationArguments = CreationArguments(requireNonBlankNames = false) |
| 82 | + ) { |
| 83 | + initialState() |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + "check exception thrown on machine start with blank names and enabled check" { |
| 88 | + val machine = createTestStateMachine( |
| 89 | + coroutineStarterType, |
| 90 | + start = false, |
| 91 | + creationArguments = CreationArguments(requireNonBlankNames = true) |
| 92 | + ) { |
| 93 | + initialState() |
| 94 | + } |
| 95 | + shouldThrow<IllegalStateException> { |
| 96 | + machine.start() |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | +}) |
0 commit comments