PreDeletionHooksConfiguration { public static PreDeletionHooksConfiguration from(HierarchicalConfiguration<ImmutableNode> configuration) throws ConfigurationException { List<HierarchicalConfiguration<ImmutableNode>> entries = configuration.configurationsAt(CONFIGURATION_ENTRY_NAME); return new PreDeletionHooksConfiguration(entries .stream() .map(Throwing.function(PreDeletionHookConfiguration::from).sneakyThrow()) .collect(Guavate.toImmutableList())); } @VisibleForTesting  PreDeletionHooksConfiguration(List<PreDeletionHookConfiguration> hooksConfiguration); static PreDeletionHooksConfiguration from(HierarchicalConfiguration<ImmutableNode> configuration); static PreDeletionHooksConfiguration forHooks(PreDeletionHookConfiguration... hooks); static PreDeletionHooksConfiguration none(); List<PreDeletionHookConfiguration> getHooksConfiguration(); @Override final boolean equals(Object o); @Override final int hashCode();  }
@Test void fromShouldThrowWhenInvalidHookConfiguration() throws Exception { XMLConfiguration configuration = FileConfigurationProvider.getConfig(new ByteArrayInputStream(( "<preDeletionHooks>" + " <preDeletionHook>" + " <class></class>" + " </preDeletionHook>" + "</preDeletionHooks>") .getBytes(StandardCharsets.UTF_8))); HierarchicalConfiguration<ImmutableNode> invalidConfigurationEntry = new BaseHierarchicalConfiguration(); configuration.addProperty(PreDeletionHooksConfiguration.CONFIGURATION_ENTRY_NAME, ImmutableList.of(invalidConfigurationEntry)); assertThatThrownBy(() -> PreDeletionHooksConfiguration.from(configuration)) .isInstanceOf(ConfigurationException.class); }
@Test void fromShouldReturnConfiguredEntry() throws Exception { XMLConfiguration configuration = FileConfigurationProvider.getConfig(new ByteArrayInputStream(( "<preDeletionHooks>" + " <preDeletionHook>" + " <class>a.class</class>" + " </preDeletionHook>" + "</preDeletionHooks>") .getBytes(StandardCharsets.UTF_8))); String className = "a.class"; assertThat(PreDeletionHooksConfiguration.from(configuration)) .isEqualTo(new PreDeletionHooksConfiguration(ImmutableList.of(PreDeletionHookConfiguration.forClass(className)))); }
@Test void fromShouldReturnAllConfiguredEntries() throws Exception { XMLConfiguration configuration = FileConfigurationProvider.getConfig(new ByteArrayInputStream(( "<preDeletionHooks>" + " <preDeletionHook>" + " <class>a.class</class>" + " </preDeletionHook>" + " <preDeletionHook>" + " <class>b.class</class>" + " </preDeletionHook>" + "</preDeletionHooks>") .getBytes(StandardCharsets.UTF_8))); String className1 = "a.class"; String className2 = "b.class"; assertThat(PreDeletionHooksConfiguration.from(configuration)) .isEqualTo(new PreDeletionHooksConfiguration(ImmutableList.of( PreDeletionHookConfiguration.forClass(className1), PreDeletionHookConfiguration.forClass(className2)))); }