aglinxinyuan commented on code in PR #4738:
URL: https://github.com/apache/texera/pull/4738#discussion_r3177512405


##########
amber/src/test/scala/org/apache/texera/amber/engine/common/statetransition/StateManagerSpec.scala:
##########
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.amber.engine.common.statetransition
+
+import org.apache.texera.amber.core.virtualidentity.ActorVirtualIdentity
+import org.apache.texera.amber.engine.common.statetransition.StateManager.{
+  InvalidStateException,
+  InvalidTransitionException
+}
+import org.scalatest.flatspec.AnyFlatSpec
+
+class StateManagerSpec extends AnyFlatSpec {
+
+  private sealed trait DummyState
+  private case object S0 extends DummyState
+  private case object S1 extends DummyState
+  private case object S2 extends DummyState
+  private case object Orphan extends DummyState
+
+  private val actorId: ActorVirtualIdentity = 
ActorVirtualIdentity("test-actor")
+
+  /** Linear graph S0 -> S1 -> S2; S2 is terminal. Orphan is unreachable. */
+  private def linear(initial: DummyState = S0): StateManager[DummyState] =
+    new StateManager[DummyState](
+      actorId,
+      Map(
+        S0 -> Set(S1),
+        S1 -> Set(S2),
+        S2 -> Set.empty
+      ),
+      initial
+    )
+
+  "StateManager" should "report the initial state via getCurrentState" in {
+    assert(linear(S1).getCurrentState == S1)
+  }
+
+  "StateManager.transitTo" should "advance to a state listed as a successor in 
the transition graph" in {
+    val sm = linear()
+    sm.transitTo(S1)
+    assert(sm.getCurrentState == S1)
+  }
+
+  it should "be a no-op when transitioning to the current state" in {
+    val sm = linear(S1)
+    sm.transitTo(S1)
+    assert(sm.getCurrentState == S1)
+  }
+
+  it should "throw InvalidTransitionException when the target is not a 
successor of the current state" in {
+    val sm = linear()
+    val ex = intercept[InvalidTransitionException] {
+      sm.transitTo(S2)
+    }
+    assert(ex.getMessage.contains(S0.toString))
+    assert(ex.getMessage.contains(S2.toString))
+  }
+
+  it should "throw InvalidTransitionException for a state absent from the 
transition graph keys" in {
+    val sm = linear(S2) // S2 has no outgoing transitions
+    intercept[InvalidTransitionException] {
+      sm.transitTo(Orphan)
+    }
+  }
+

Review Comment:
   Done in 3ae9138d33. Renamed the existing case to match what it actually 
asserts ("transitioning out of a terminal state with no listed successors") and 
added a separate case that drives the absent-key path by initializing with 
`Orphan`, which is intentionally not a key in `linear()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to