Copilot commented on code in PR #4738: URL: https://github.com/apache/texera/pull/4738#discussion_r3177467950
########## 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: The test case labeled "throw InvalidTransitionException for a state absent from the transition graph keys" doesn't actually cover the "absent from graph keys" scenario: `S2` is present as a key in `linear()` (with `Set.empty`), and `StateManager.transitTo` only consults `stateTransitionGraph` for the *current* state key (it doesn't require the target to be a key). This currently just tests "target not a successor" again. To cover the intended behavior, add a case where the *current* state is not in the graph keys (e.g., initialize the StateManager to `Orphan` while the graph omits `Orphan`), and assert `transitTo(...)` throws `InvalidTransitionException`. Also update the test description to match what it's asserting. -- 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]
