LibraryImportEvent { public static LibraryImportEvent from(final Map<String, Object> eventMap) { final List<?> arguments = (List<?>) eventMap.get("library_import"); final Map<?, ?> attributes = (Map<?, ?>) arguments.get(1); final String originalName = (String) attributes.get("originalname"); final URI importer = Events.toFileUri((String) attributes.get("importer")); final URI source = Events.toFileUri((String) attributes.get("source")); if (originalName == null) { throw new IllegalArgumentException("Library import event has to have original name and arguments provided"); } return new LibraryImportEvent(originalName, importer, source); } LibraryImportEvent(final String name, final URI importer, final URI source); static LibraryImportEvent from(final Map<String, Object> eventMap); String getName(); Optional<URI> getImporter(); Optional<URI> getSource(); @Override boolean equals(final Object obj); @Override int hashCode();  }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_1() { final Map<String, Object> eventMap = ImmutableMap.of(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> LibraryImportEvent.from(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_2() { final Map<String, Object> eventMap = ImmutableMap.of("library_import", new Object()); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> LibraryImportEvent.from(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_3() { final Map<String, Object> eventMap = ImmutableMap.of("library_import", newArrayList()); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> LibraryImportEvent.from(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_4() { final Map<String, Object> eventMap = ImmutableMap.of("library_import", newArrayList("_", "foo")); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> LibraryImportEvent.from(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_5() { final Map<String, Object> eventMap = ImmutableMap.of("library_import", newArrayList("_", ImmutableMap.of())); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> LibraryImportEvent.from(eventMap)); }