ListenerConfiguration { public static ListenerConfiguration from(HierarchicalConfiguration<ImmutableNode> configuration) { String listenerClass = configuration.getString("class"); Preconditions.checkState(!Strings.isNullOrEmpty(listenerClass), "class name is mandatory"); Optional<Boolean> isAsync = Optional.ofNullable(configuration.getBoolean("async", null)); Optional<String> group = Optional.ofNullable(configuration.getString("group", null)); return new ListenerConfiguration(listenerClass, group, extractSubconfiguration(configuration), isAsync); } private  ListenerConfiguration(String clazz, Optional<String> group, Optional<HierarchicalConfiguration<ImmutableNode>> configuration, Optional<Boolean> isAsync); static ListenerConfiguration from(HierarchicalConfiguration<ImmutableNode> configuration); static ListenerConfiguration forClass(String clazz); Optional<String> getGroup(); String getClazz(); Optional<HierarchicalConfiguration<ImmutableNode>> getConfiguration(); Optional<Boolean> isAsync();  }
@Test void fromShouldThrowWhenClassIsNotInTheConfiguration() { BaseHierarchicalConfiguration configuration = new BaseHierarchicalConfiguration(); assertThatThrownBy(() -> ListenerConfiguration.from(configuration)) .isInstanceOf(IllegalStateException.class); }
@Test void fromShouldThrowWhenClassIsEmpty() { BaseHierarchicalConfiguration configuration = new BaseHierarchicalConfiguration(); configuration.addProperty("class", ""); assertThatThrownBy(() -> ListenerConfiguration.from(configuration)) .isInstanceOf(IllegalStateException.class); }