/*
 * 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.descriptor;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.gen5.api.Assertions.assertThrows;

import java.lang.reflect.Method;

import org.junit.gen5.api.Test;
import org.junit.gen5.api.TestInfo;
import org.junit.gen5.commons.util.PreconditionViolationException;

/**
 * Unit tests for {@link JavaPackageSource}, {@link JavaClassSource}, and
 * {@link JavaMethodSource}.
 *
 * @since 5.0
 */
class JavaSourceTests {

	@Test
	void packageSourceFromNullPackageName() {
		assertThrows(PreconditionViolationException.class, () -> new JavaPackageSource((String) null));
	}

	@Test
	void packageSourceFromEmptyPackageName() {
		assertThrows(PreconditionViolationException.class, () -> new JavaPackageSource("  "));
	}

	@Test
	void packageSourceFromPackageName() {
		String testPackage = getClass().getPackage().getName();
		JavaPackageSource source = new JavaPackageSource(testPackage);

		assertThat(source.getPackageName()).isEqualTo(testPackage);
	}

	@Test
	void packageSourceFromNullPackageReference() {
		assertThrows(PreconditionViolationException.class, () -> new JavaPackageSource((Package) null));
	}

	@Test
	void packageSourceFromPackageReference() {
		Package testPackage = getClass().getPackage();
		JavaPackageSource source = new JavaPackageSource(testPackage);

		assertThat(source.getPackageName()).isEqualTo(testPackage.getName());
	}

	@Test
	void classSource() {
		Class<?> testClass = getClass();
		JavaClassSource source = new JavaClassSource(testClass);

		assertThat(source.getJavaClass()).isEqualTo(testClass);
	}

	@Test
	void methodSource(TestInfo testInfo) throws Exception {
		Class<?> testClass = JavaSourceTests.class;
		String testName = testInfo.getDisplayName();
		Method testMethod = testClass.getDeclaredMethod(testName, TestInfo.class);
		JavaMethodSource source = new JavaMethodSource(testMethod);

		assertThat(source.getJavaClass()).isEqualTo(testClass);
		assertThat(source.getJavaMethodName()).isEqualTo(testName);
		assertThat(source.getJavaMethodParameterTypes()).containsExactly(TestInfo.class);
	}

}

@@ -416,16 +416,133 @@
 rtThat;%0A
+import static org.junit.gen5.api.Assertions.assertEquals;%0Aimport static org.junit.gen5.api.Assertions.assertNotSame;%0A
 import s
@@ -2063,25 +2063,8 @@
 rce(
-TestInfo testInfo
 ) th
@@ -2086,173 +2086,497 @@
 %7B%0A%09%09
-Class%3C?%3E testClass = JavaSourceTests.c
+Method testMethod = getExampleMethod();%0A%09%09JavaMethodSource source = new JavaMethodSource(testMethod);%0A%0A%09%09assertThat(source.getJavaClass()).isEqualTo(getC
 lass
+())
 ;%0A%09%09
-String testName = testInfo.getDisplay
+assertThat(source.getJavaMethodName()).isEqualTo(testMethod.get
 Name()
+)
 ;%0A%09%09
-Method testMethod = tes
+assertThat(source.getJavaMethodParameterTypes()).containsExactly(String.class);%0A%09%7D%0A%0A%09@Test%0A%09void equalsAndHashCodeForJavaPackageSource() %7B%0A%09%09Package testPackage = ge
 tClass
+()
 .get
-DeclaredMethod(testName, TestInfo.class
+Package();%0A%09%09JavaPackageSource source1 = new JavaPackageSource(testPackage
 );%0A%09
@@ -2572,38 +2572,39 @@
 Package);%0A%09%09Java
-Method
+Package
 Source source = 
@@ -2592,32 +2592,33 @@
 ageSource source
+2
  = new JavaMetho
@@ -2604,38 +2604,39 @@
 urce2 = new Java
-Method
+Package
 Source(testMetho
@@ -2634,213 +2634,970 @@
 test
-Method);%0A%0A%09%09assertThat(source.getJavaClass()).isEqualTo(testClass);%0A%09%09assertThat(source.getJavaMethodName()).isEqualTo(testName);%0A%09%09assertThat(source.getJavaMethodParameterTypes()).containsExactly(TestInfo
+Package);%0A%0A%09%09assertNotSame(source1, source2);%0A%09%09assertEquals(source1, source2);%0A%09%09assertEquals(source1.hashCode(), source2.hashCode());%0A%09%7D%0A%0A%09@Test%0A%09void equalsAndHashCodeForJavaClassSource() %7B%0A%09%09Class%3C?%3E testClass = getClass();%0A%09%09JavaClassSource source1 = new JavaClassSource(testClass);%0A%09%09JavaClassSource source2 = new JavaClassSource(testClass);%0A%0A%09%09assertNotSame(source1, source2);%0A%09%09assertEquals(source1, source2);%0A%09%09assertEquals(source1.hashCode(), source2.hashCode());%0A%09%7D%0A%0A%09@Test%0A%09void equalsAndHashCodeForJavaMethodSource(TestInfo testInfo) throws Exception %7B%0A%09%09Method testMethod = getExampleMethod();%0A%09%09JavaMethodSource source1 = new JavaMethodSource(testMethod);%0A%09%09JavaMethodSource source2 = new JavaMethodSource(testMethod);%0A%0A%09%09assertNotSame(source1, source2);%0A%09%09assertEquals(source1, source2);%0A%09%7D%0A%0A%09void exampleMethod(String text) %7B%0A%09%7D%0A%0A%09private Method getExampleMethod() throws Exception %7B%0A%09%09return getClass().getDeclaredMethod(%22exampleMethod%22, String
 .cla

Test equals() & hashCode() in TestSource implementations