Fix warning on TestStateMachine (#23744)

This warning was bugging me, so I fixed it. That being said,
this warning does point to a strange circular dependency between
the transitions and the state machine where the state machine owns
transitions, but transitions can post events to the state machine.
It was abstracted out somewhat by the virtual Context interface,
but that still leaves us with this circular dependency. A better
solution would be to fix this circular dependency.

One solution would be to have the transitions table either return
a state or an event, and have the state machine dispatch to itself
rather than having the transitions hold a reference back to the
state machine. Then the transitions would only need to know about
states and events.
diff --git a/src/lib/support/tests/TestStateMachine.cpp b/src/lib/support/tests/TestStateMachine.cpp
index da29ce8..cef020e 100644
--- a/src/lib/support/tests/TestStateMachine.cpp
+++ b/src/lib/support/tests/TestStateMachine.cpp
@@ -18,6 +18,7 @@
 
 #include <lib/support/StateMachine.h>
 #include <lib/support/UnitTestRegistration.h>
+#include <lib/support/Variant.h>
 #include <nlunit-test.h>
 
 namespace {
@@ -64,28 +65,31 @@
     void LogTransition(const char * previous) { mMock.LogTransition(previous); }
     const char * GetName() { return mName; }
 
-    chip::StateMachine::Context<Event> & mCtx;
+    Context * mCtx;
     const char * mName;
     MockState & mMock;
 };
 
 struct State1 : public BaseState
 {
-    State1(Context & ctx, MockState & mock) : BaseState{ ctx, "State1", mock } {}
+    State1(Context * ctx, MockState & mock) : BaseState{ ctx, "State1", mock } {}
 };
 
 struct State2 : public BaseState
 {
-    State2(Context & ctx, MockState & mock) : BaseState{ ctx, "State2", mock } {}
+    State2(Context * ctx, MockState & mock) : BaseState{ ctx, "State2", mock } {}
 };
 
 struct State3 : public BaseState
 {
-    State3(Context & ctx, MockState & mock) : BaseState{ ctx, "State3", mock } {}
+    State3(Context * ctx, MockState & mock) : BaseState{ ctx, "State3", mock } {}
     void Enter()
     {
         BaseState::Enter();
-        this->mCtx.Dispatch(Event::Create<Event5>());
+        if (this->mCtx)
+        {
+            this->mCtx->Dispatch(Event::Create<Event5>());
+        }
     }
 };
 
@@ -95,12 +99,12 @@
 
 struct StateFactory
 {
-    Context & mCtx;
+    Context * mCtx;
     MockState ms1{ 0, 0, 0, nullptr };
     MockState ms2{ 0, 0, 0, nullptr };
     MockState ms3{ 0, 0, 0, nullptr };
 
-    StateFactory(Context & ctx) : mCtx(ctx) {}
+    StateFactory(Context * ctx) : mCtx(ctx) {}
 
     auto CreateState1() { return State::Create<State1>(mCtx, ms1); }
     auto CreateState2() { return State::Create<State2>(mCtx, ms2); }
@@ -109,9 +113,9 @@
 
 struct Transitions
 {
-    Context & mCtx;
+    Context * mCtx;
     StateFactory mFactory;
-    Transitions(Context & ctx) : mCtx(ctx), mFactory(ctx) {}
+    Transitions(Context * ctx) : mCtx(ctx), mFactory(ctx) {}
 
     using OptState = chip::StateMachine::Optional<State>;
     State GetInitState() { return mFactory.CreateState1(); }
@@ -128,7 +132,10 @@
         if (state.Is<State1>() && event.Is<Event4>())
         {
             // legal - Dispatches event without transition
-            mCtx.Dispatch(Event::Create<Event2>());
+            if (mCtx)
+            {
+                mCtx->Dispatch(Event::Create<Event2>());
+            }
             return {};
         }
         if (state.Is<State2>() && event.Is<Event4>())
@@ -155,7 +162,7 @@
     Transitions mTransitions;
     chip::StateMachine::StateMachine<State, Event, Transitions> mStateMachine;
 
-    SimpleStateMachine() : mTransitions(mStateMachine), mStateMachine(mTransitions) {}
+    SimpleStateMachine() : mTransitions(&mStateMachine), mStateMachine(mTransitions) {}
     ~SimpleStateMachine() {}
 };