EventFactory { public static <T extends ProjectEvent> T projectEvent(Class<T> eventClass, Project project) { try { T event = eventClass.newInstance(); ZonedDateTime now = now(); event.setId(uuid()); event.setTimestamp(now); event.setProject(project); return event; } catch (Exception e) { throw new RuntimeException(e); } }  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 testProjectEvent() throws Exception { Project project = new Project(); ZonedDateTime timestamp = now(); project.setTimestamp(timestamp); ProjectSyncEvent event1 = projectEvent(ProjectSyncEvent.class, project); Thread.sleep(50); ProjectSyncEvent event2 = projectEvent(ProjectSyncEvent.class, project); assertThat(event1.getId(), not(equalTo(event2.getId()))); assertThat(event1.getTimestamp(), not(equalTo(event2.getTimestamp()))); assertThat(event1.getProject(), equalTo(event2.getProject())); assertThat(event1.getProject().getTimestamp(), equalTo(timestamp)); }