/*
 * Copyright 2015-2016 the original author or authors.
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution and is available at
 *
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.junit.gen5.engine.support.filter;

import static org.junit.gen5.commons.meta.API.Usage.Internal;

import java.util.Optional;
import java.util.function.BiConsumer;

import org.junit.gen5.commons.meta.API;
import org.junit.gen5.engine.Filter;
import org.junit.gen5.engine.FilterResult;

/**
 * @since 5.0
 */
@API(Internal)
public class ExclusionReasonConsumingFilter<T> implements Filter<T> {

	private final Filter<T> filter;
	private final BiConsumer<T, Optional<String>> reasonConsumer;

	public ExclusionReasonConsumingFilter(Filter<T> filter, BiConsumer<T, Optional<String>> reasonConsumer) {
		this.filter = filter;
		this.reasonConsumer = reasonConsumer;
	}

	@Override
	public FilterResult apply(T object) {
		FilterResult result = this.filter.apply(object);
		if (result.excluded()) {
			this.reasonConsumer.accept(object, result.getReason());
		}
		return result;
	}

}

@@ -523,16 +523,66 @@
 ta.API;%0A
+import org.junit.gen5.commons.util.Preconditions;%0A
 import o
@@ -658,16 +658,169 @@
 t;%0A%0A/**%0A
+ * Decorator for a %7B@link Filter%7D that passes the %3Cem%3Eobject%3C/em%3E and the%0A * %3Cem%3Ereason%3C/em%3E to a %7B@link BiConsumer%7D in case it is %3Cem%3Eexcluded%3C/em%3E.%0A *%0A
  * @sinc
@@ -1017,176 +1017,582 @@
 ;%0A%0A%09
-public ExclusionReasonConsumingFilter(Filter%3CT%3E filter, BiConsumer%3CT, Optional%3CString%3E%3E reasonConsumer) %7B%0A%09%09this.filter = filter;%0A%09%09this.reasonConsumer = reasonConsumer
+/**%0A%09 * Create a new %7B@code ExclusionReasonConsumingFilter%7D using the supplied%0A%09 * %7B@code filter%7D and %7B@code reasonConsumer%7D.%0A%09 *%0A%09 * @param filter the filter to decorate; must not be %7B@code null%7D%0A%09 * @param reasonConsumer the consumer to call in case of exclusions; must not be %7B@code null%7D%0A%09 */%0A%09public ExclusionReasonConsumingFilter(Filter%3CT%3E filter, BiConsumer%3CT, Optional%3CString%3E%3E reasonConsumer) %7B%0A%09%09this.filter = Preconditions.notNull(filter, %22filter must not be null%22);%0A%09%09this.reasonConsumer = Preconditions.notNull(reasonConsumer, %22reasonConsumer must not be null%22)
 ;%0A%09%7D

Document ExclusionReasonConsumingFilter (#234)