EventFactory { public static ImageState imageEventToState(ImageEvent event) { if (event instanceof ImageDeletingEvent) { return ImageState.DELETING; } else if (event instanceof ImageErrorEvent) { return ImageState.ERROR; } else if (event instanceof ImageQueuedEvent) { return ImageState.QUEUED; } else if (event instanceof ImageSavingEvent) { return ImageState.SAVING; } else if (event instanceof ImageSavedEvent) { return ImageState.SAVED; } 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 testImageEventToState() { assertThat(imageEventToState(new ImageDeletingEvent()), equalTo(ImageState.DELETING)); assertThat(imageEventToState(new ImageErrorEvent()), equalTo(ImageState.ERROR)); assertThat(imageEventToState(new ImageQueuedEvent()), equalTo(ImageState.QUEUED)); assertThat(imageEventToState(new ImageSavingEvent()), equalTo(ImageState.SAVING)); assertThat(imageEventToState(new ImageSavedEvent()), equalTo(ImageState.SAVED)); }