EventFactory { public static InstanceState instanceEventToState(InstanceEvent event) { if (event instanceof InstanceDeletingEvent) { return DELETING; } else if (event instanceof InstanceErrorEvent) { return ERROR; } else if (event instanceof InstanceHardRebootingEvent) { return HARD_REBOOTING; } else if (event instanceof InstanceLaunchedEvent) { return LAUNCHED; } else if (event instanceof InstanceLaunchingEvent) { return LAUNCHING; } else if (event instanceof InstanceMigratingEvent) { return MIGRATING; } else if (event instanceof InstancePausedEvent) { return PAUSED; } else if (event instanceof InstancePausingEvent) { return PAUSING; } else if (event instanceof InstanceQueuedEvent) { return QUEUED; } else if (event instanceof InstanceRebootingEvent) { return REBOOTING; } else if (event instanceof InstanceRebuildingEvent) { return REBUILDING; } else if (event instanceof InstanceResizingEvent) { return RESIZING; } else if (event instanceof InstanceResumingEvent) { return RESUMING; } else if (event instanceof InstanceShutOffEvent) { return SHUTOFF; } else if (event instanceof InstanceShuttingDownEvent) { return SHUTTING_DOWN; } else if (event instanceof InstanceStartingEvent) { return STARTING; } else if (event instanceof InstanceSuspendingEvent) { return SUSPENDING; } else if (event instanceof InstanceSuspendedEvent) { return SUSPENDED; } throw new IllegalArgumentException("Unsupported event: " + event.getClass().getSimpleName()); }  static T instanceEvent(Class<T> eventClass, Instance instance); static InstanceEvent instanceToEvent(Instance instance); static InstanceState instanceEventToState(InstanceEvent event); static T imageEvent(Class<T> eventClass, Image image); static ImageEvent imageToEvent(Image image); static ImageState imageEventToState(ImageEvent event); static T projectEvent(Class<T> eventClass, Project project); static String uuid(); static ZonedDateTime now();  }
@Test public void testEventToState() { assertThat(instanceEventToState(new InstanceDeletingEvent()), equalTo(DELETING)); assertThat(instanceEventToState(new InstanceErrorEvent()), equalTo(ERROR)); assertThat(instanceEventToState(new InstanceHardRebootingEvent()), equalTo(HARD_REBOOTING)); assertThat(instanceEventToState(new InstanceLaunchedEvent()), equalTo(LAUNCHED)); assertThat(instanceEventToState(new InstanceLaunchingEvent()), equalTo(LAUNCHING)); assertThat(instanceEventToState(new InstanceMigratingEvent()), equalTo(MIGRATING)); assertThat(instanceEventToState(new InstancePausedEvent()), equalTo(PAUSED)); assertThat(instanceEventToState(new InstancePausingEvent()), equalTo(PAUSING)); assertThat(instanceEventToState(new InstanceQueuedEvent()), equalTo(QUEUED)); assertThat(instanceEventToState(new InstanceRebootingEvent()), equalTo(REBOOTING)); assertThat(instanceEventToState(new InstanceRebuildingEvent()), equalTo(REBUILDING)); assertThat(instanceEventToState(new InstanceResizingEvent()), equalTo(RESIZING)); assertThat(instanceEventToState(new InstanceResumingEvent()), equalTo(RESUMING)); assertThat(instanceEventToState(new InstanceShutOffEvent()), equalTo(SHUTOFF)); assertThat(instanceEventToState(new InstanceShuttingDownEvent()), equalTo(SHUTTING_DOWN)); assertThat(instanceEventToState(new InstanceStartingEvent()), equalTo(STARTING)); assertThat(instanceEventToState(new InstanceSuspendingEvent()), equalTo(SUSPENDING)); assertThat(instanceEventToState(new InstanceSuspendedEvent()), equalTo(SUSPENDED)); }
@Test(expected = IllegalArgumentException.class) public void testWrongEventToState() { instanceEventToState(new InstanceSnapshottingEvent()); }