/*
 * Copyright 2015-2017 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.jupiter.engine.discovery.predicates;

import static org.assertj.core.api.Assertions.assertThat;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Predicate;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
import org.junit.platform.commons.util.ReflectionUtils;

/**
 * Unit tests for {@link IsTestFactoryMethod}.
 *
 * @since 5.0
 */
class IsTestFactoryMethodTests {

	private static final Predicate<Method> isTestFactoryMethod = new IsTestFactoryMethod();

	@Test
	void factoryMethodReturningCollectionOfDynamicTests() {
		assertThat(isTestFactoryMethod).accepts(method("dynamicTestsFactory"));
	}

	@Test
	void bogusFactoryMethodReturningVoid() {
		assertThat(isTestFactoryMethod).rejects(method("bogusVoidFactory"));
	}

	@Disabled("Disabled until IsTestFactoryMethod properly checks return type")
	@Test
	void bogusFactoryMethodReturningObject() {
		assertThat(isTestFactoryMethod).rejects(method("bogusObjectFactory"));
	}

	@Disabled("Disabled until IsTestFactoryMethod properly checks return type")
	@Test
	void bogusFactoryMethodReturningCollectionOfStrings() {
		assertThat(isTestFactoryMethod).rejects(method("bogusStringsFactory"));
	}

	private static Method method(String name) {
		return ReflectionUtils.findMethod(ClassWithTestFactoryMethods.class, name).get();
	}

	private static class ClassWithTestFactoryMethods {

		@TestFactory
		Collection<DynamicTest> dynamicTestsFactory() {
			return new ArrayList<>();
		}

		@TestFactory
		void bogusVoidFactory() {
		}

		@TestFactory
		Object bogusObjectFactory() {
			return new Object();
		}

		@TestFactory
		Collection<String> bogusStringsFactory() {
			return new ArrayList<>();
		}

	}

}

@@ -1219,32 +1219,114 @@
 Factory%22));%0A%09%7D%0A%0A
+%09// TODO %5B#949%5D Enable test once IsTestFactoryMethod properly checks return type.%0A
 %09@Disabled(%22Disa
@@ -1514,16 +1514,98 @@
 ));%0A%09%7D%0A%0A
+%09// TODO %5B#949%5D Enable test once IsTestFactoryMethod properly checks return type.%0A
 %09@Disabl

Add TODOs for #949