EventFactory { public static ImageEvent imageToEvent(Image image) { ImageState imageState = image.getState(); ImageEvent event = imageStateToEvent(imageState); event.setImage(image); 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 testImageToEvent() { testImageToEvent(ImageState.DELETING, ImageDeletingEvent.class); testImageToEvent(ImageState.ERROR, ImageErrorEvent.class); testImageToEvent(ImageState.QUEUED, ImageQueuedEvent.class); testImageToEvent(ImageState.SAVING, ImageSavingEvent.class); testImageToEvent(ImageState.SAVED, ImageSavedEvent.class); }
@Test(expected = IllegalArgumentException.class) public void testImageToEventWrongState() { Image image = new Image(); image.setState(null); imageToEvent(image); }