public static TriggerStateMachine stateMachineForTrigger(RunnerApi.Trigger trigger) {
    switch (trigger.getTriggerCase()) {
      case AFTER_ALL:
        return AfterAllStateMachine.of(
            stateMachinesForTriggers(trigger.getAfterAll().getSubtriggersList()));
      case AFTER_ANY:
        return AfterFirstStateMachine.of(
            stateMachinesForTriggers(trigger.getAfterAny().getSubtriggersList()));
      case AFTER_END_OF_WINDOW:
        return stateMachineForAfterEndOfWindow(trigger.getAfterEndOfWindow());
      case ELEMENT_COUNT:
        return AfterPaneStateMachine.elementCountAtLeast(
            trigger.getElementCount().getElementCount());
      case AFTER_SYNCHRONIZED_PROCESSING_TIME:
        return AfterSynchronizedProcessingTimeStateMachine.ofFirstElement();
      case DEFAULT:
        return DefaultTriggerStateMachine.of();
      case NEVER:
        return NeverStateMachine.ever();
      case ALWAYS:
        return ReshuffleTriggerStateMachine.create();
      case OR_FINALLY:
        return stateMachineForTrigger(trigger.getOrFinally().getMain())
            .orFinally(stateMachineForTrigger(trigger.getOrFinally().getFinally()));
      case REPEAT:
        return RepeatedlyStateMachine.forever(
            stateMachineForTrigger(trigger.getRepeat().getSubtrigger()));
      case AFTER_EACH:
        return AfterEachStateMachine.inOrder(
            stateMachinesForTriggers(trigger.getAfterEach().getSubtriggersList()));
      case AFTER_PROCESSING_TIME:
        return stateMachineForAfterProcessingTime(trigger.getAfterProcessingTime());
      case TRIGGER_NOT_SET:
        throw new IllegalArgumentException(
            String.format("Required field 'trigger' not set on %s", trigger));
      default:
        throw new IllegalArgumentException(String.format("Unknown trigger type %s", trigger));
    }
  }
@Test
  public void testAfterAllTranslation() {
    RunnerApi.Trigger trigger =
        RunnerApi.Trigger.newBuilder()
            .setAfterAll(
                RunnerApi.Trigger.AfterAll.newBuilder()
                    .addSubtriggers(subtrigger1)
                    .addSubtriggers(subtrigger2))
            .build();
    AfterAllStateMachine machine =
        (AfterAllStateMachine) TriggerStateMachines.stateMachineForTrigger(trigger);

    assertThat(machine, equalTo(AfterAllStateMachine.of(submachine1, submachine2)));
  }