Feature implements IFeature { @Override public void listen() throws FeatureManagementException { synchronized (lock) { if (0 == required.size()) { throw new FeatureManagementException("No items defined for this feature."); } if (null != paths) { throw new FeatureManagementException("Items for this feature are already resolved (#listen called twice)."); } this.paths = manager.resolveArtifacts(this.required); List<Throwable> exceptions = new LinkedList<>(); for (IAction<Collection<IPath>> action : listeners) { try { action.execute(paths); } catch (Exception e) { exceptions.add(e); } } if (exceptions.size() != 0) { Throwable e = exceptions.remove(0); for (Throwable ee : exceptions) { e.addSuppressed(ee); } throw new FeatureManagementException("Error(s) occurred notifying feature listeners.", e); } } } Feature(final DependencyResolvingFeatureManager manager, final String name); @Override void requireFile(final String fileName); @Override void whenPresent(final IAction<Collection<IPath>> action); @Override void listen(); @Override String getName();  }
@Test(expected = FeatureManagementException.class) public void Should_throw_When_listenCalledBeforeAnyArtifactsRequired() throws Exception { IFeature feature = new Feature(managerMock, "feature"); feature.listen(); }