/*
 * 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.platform.commons.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

import java.util.function.Supplier;

import org.junit.jupiter.api.Test;

/**
 * Unit tests for {@link PackageUtils}.
 *
 * @since 1.0
 */
class PackageUtilsTests {

	@Test
	void getAttributeWithNullType() {
		PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> {
			PackageUtils.getAttribute(null, null);
		});
		assertEquals("type must not be null", exception.getMessage());
	}

	@Test
	void getAttributeWithNullFunction() {
		PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> {
			PackageUtils.getAttribute(getClass(), null);
		});
		assertEquals("function must not be null", exception.getMessage());
	}

	@Test
	void getAttributeWithFunctionReturningNullIsEmpty() {
		assertFalse(PackageUtils.getAttribute(Object.class, p -> null).isPresent());
	}

	@Test
	void vendorFromObjectClassIsPresent() {
		assumeFalse(System.getProperty("java.version").startsWith("9"), "Java 9 not supported, yet");
		assertTrue(PackageUtils.getAttribute(Object.class, Package::getSpecificationVendor).isPresent());
		assertTrue(PackageUtils.getAttribute(Object.class, Package::getImplementationVendor).isPresent());
	}

	@Test
	void versionSystemPropertyEqualsRuntimeClassImplementationVersion() {
		assumeFalse(System.getProperty("java.version").startsWith("9"), "Java 9 not supported, yet");
		Supplier<AssertionError> error = () -> new AssertionError("implementation version not available");
		String actual = PackageUtils.getAttribute(Runtime.class, Package::getImplementationVersion).orElseThrow(error);
		assertEquals(System.getProperty("java.version"), actual);
	}

}

@@ -630,104 +630,322 @@
 api.
-Assumptions.assumeFalse;%0A%0Aimport java.util.function.Supplier;%0A%0Aimport org.junit.jupiter.api.Test
+DynamicTest.dynamicTest;%0A%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.function.Function;%0A%0Aimport org.junit.jupiter.api.DynamicTest;%0Aimport org.junit.jupiter.api.Test;%0Aimport org.junit.jupiter.api.TestFactory;%0Aimport org.junit.jupiter.api.function.Executable;%0Aimport org.opentest4j.ValueWrapper
 ;%0A%0A/
@@ -1669,38 +1669,44 @@
 ls.getAttribute(
-Object
+ValueWrapper
 .class, p -%3E nul
@@ -1736,38 +1736,69 @@
 Test
-%0A%09void vendorFromObject
+Factory%0A%09List%3CDynamicTest%3E attributesFromValueWrapper
 Class
-Is
+Are
 Pres
@@ -1811,641 +1811,568 @@
 %7B%0A%09%09
-assumeFalse(System.getProperty(%22java.version%22).startsWith(%229%22), %22Java 9 not supported, yet%22);%0A%09%09assertTrue(PackageUtils.getAttribute(Object.class, Package::getSpecificationVendor).isPresent());%0A%09%09assertTrue(PackageUtils.getAttribute(Object.class, Package::getImplementationVendor).isPresent());%0A%09%7D%0A%0A%09@Test%0A%09void versionSystemPropertyEqualsRuntimeClassImplementationVersion() %7B%0A%09%09assumeFalse(System.getProperty(%22java.version%22).startsWith(%229%22), %22Java 9 not supported, yet%22);%0A%09%09Supplier%3CAssertionError%3E error = () -%3E new AssertionError(%22implementation version not available%22);%0A%09%09String actual = PackageUtils.getAttribute(Runtime.class, 
+return Arrays.asList(dynamicTest(%22getName%22, isPresent(Package::getName)),%0A%09%09%09dynamicTest(%22getImplementationTitle%22, isPresent(Package::getImplementationTitle)),%0A%09%09%09dynamicTest(%22getImplementationVendor%22, isPresent(Package::getImplementationVendor)),%0A%09%09%09dynamicTest(%22getImplementationVersion%22, isPresent(Package::getImplementationVersion)),%0A%09%09%09dynamicTest(%22getSpecificationTitle%22, isPresent(Package::getSpecificationTitle)),%0A%09%09%09dynamicTest(%22getSpecificationVendor%22, isPresent(Package::getSpecificationVendor)),%0A%09%09%09dynamicTest(%22getSpecificationVersion%22, isPresent(
 Pack
@@ -2375,33 +2375,32 @@
 Package::get
-Implement
+Specific
 ationVersion
@@ -2404,86 +2404,177 @@
 ion)
-.orElseThrow(error);%0A%09%09assertEquals(System.getProperty(%22java.version%22), actual
+));%0A%09%7D%0A%0A%09private Executable isPresent(Function%3CPackage, String%3E function) %7B%0A%09%09return () -%3E assertTrue(PackageUtils.getAttribute(ValueWrapper.class, function).isPresent()
 );%0A%09

Test PackageUtils with class from external JAR