EventFactory { public static InstanceEvent instanceToEvent(Instance instance) { InstanceState instanceState = instance.getState(); InstanceEvent event = instanceStateToEvent(instanceState); event.setInstance(instance); event.setId(uuid()); event.setTimestamp(now()); return event; }  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 testInstanceToEvent() { testInstanceToEvent(DELETING, InstanceDeletingEvent.class); testInstanceToEvent(ERROR, InstanceErrorEvent.class); testInstanceToEvent(HARD_REBOOTING, InstanceHardRebootingEvent.class); testInstanceToEvent(LAUNCHED, InstanceLaunchedEvent.class); testInstanceToEvent(LAUNCHING, InstanceLaunchingEvent.class); testInstanceToEvent(MIGRATING, InstanceMigratingEvent.class); testInstanceToEvent(PAUSED, InstancePausedEvent.class); testInstanceToEvent(PAUSING, InstancePausingEvent.class); testInstanceToEvent(QUEUED, InstanceQueuedEvent.class); testInstanceToEvent(REBOOTING, InstanceRebootingEvent.class); testInstanceToEvent(REBUILDING, InstanceRebuildingEvent.class); testInstanceToEvent(RESIZING, InstanceResizingEvent.class); testInstanceToEvent(RESUMING, InstanceResumingEvent.class); testInstanceToEvent(SHUTOFF, InstanceShutOffEvent.class); testInstanceToEvent(SHUTTING_DOWN, InstanceShuttingDownEvent.class); testInstanceToEvent(STARTING, InstanceStartingEvent.class); testInstanceToEvent(SUSPENDING, InstanceSuspendingEvent.class); testInstanceToEvent(SUSPENDED, InstanceSuspendedEvent.class); }
@Test(expected = IllegalArgumentException.class) public void testInstanceToEventWrongState() { Instance instance = new Instance(); instance.setState(null); instanceToEvent(instance); }