SyncProcessStateTransitionValidator { public boolean validate(SyncProcessState from, SyncProcessState to) { if (from == SyncProcessState.STOPPED) { if (to == SyncProcessState.STARTING) { return true; } } else if (from == SyncProcessState.STARTING) { if (to == SyncProcessState.RUNNING || to == SyncProcessState.STOPPING || to == SyncProcessState.ERROR) { return true; } } else if (from == SyncProcessState.RUNNING) { if (to == SyncProcessState.STOPPING || to == SyncProcessState.PAUSING || to == SyncProcessState.ERROR) { return true; } } else if (from == SyncProcessState.STOPPING) { if (to == SyncProcessState.STOPPED || to == SyncProcessState.ERROR) { return true; } } else if (from == SyncProcessState.PAUSING) { if (to == SyncProcessState.PAUSED || to == SyncProcessState.ERROR) { return true; } } else if (from == SyncProcessState.PAUSED) { if (to == SyncProcessState.RESUMING || to == SyncProcessState.ERROR || to == SyncProcessState.STOPPING) { return true; } } else if (from == SyncProcessState.RESUMING) { if (to == SyncProcessState.RUNNING || to == SyncProcessState.ERROR) { return true; } } return false; }  boolean validate(SyncProcessState from, SyncProcessState to);  }
@Test public void testValidate() { validate(SyncProcessState.STOPPED, SyncProcessState.STARTING); validate(SyncProcessState.STARTING, SyncProcessState.RUNNING, SyncProcessState.STOPPING, SyncProcessState.ERROR); validate(SyncProcessState.RUNNING, SyncProcessState.STOPPING, SyncProcessState.PAUSING, SyncProcessState.ERROR); validate(SyncProcessState.PAUSING, SyncProcessState.PAUSED, SyncProcessState.ERROR); validate(SyncProcessState.PAUSED, SyncProcessState.RESUMING, SyncProcessState.ERROR, SyncProcessState.STOPPING); validate(SyncProcessState.RESUMING, SyncProcessState.RUNNING, SyncProcessState.ERROR); validate(SyncProcessState.STOPPING, SyncProcessState.STOPPED, SyncProcessState.ERROR); }