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

import static org.junit.gen5.api.Assertions.assertEquals;
import static org.junit.gen5.engine.discovery.ClassSelector.forClass;
import static org.junit.gen5.launcher.main.TestDiscoveryRequestBuilder.request;

import java.util.HashMap;

import org.junit.gen5.api.AfterEach;
import org.junit.gen5.api.BeforeEach;
import org.junit.gen5.api.Test;
import org.junit.gen5.api.TestReporter;
import org.junit.gen5.commons.reporting.ReportingEntry;
import org.junit.gen5.engine.ExecutionEventRecorder;
import org.junit.gen5.launcher.TestDiscoveryRequest;

public class ReportingTest extends AbstractJUnit5TestEngineTests {

	@Test
	public void threeReportEntriesArePublished() {
		TestDiscoveryRequest request = request().select(forClass(MyReportingTestCase.class)).build();

		ExecutionEventRecorder eventRecorder = executeTests(request);

		assertEquals(1L, eventRecorder.getTestStartedCount(), "# tests started");
		assertEquals(1L, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
		assertEquals(0L, eventRecorder.getTestFailedCount(), "# tests failed");

		assertEquals(3L, eventRecorder.getReportingEntryPublishedCount(), "# report entries published");
	}

	static class MyReportingTestCase {

		@BeforeEach
		void before(TestReporter reporter) {
			reporter.publishEntry(new ReportingEntry(new HashMap<>()));
		}

		@AfterEach
		void after(TestReporter reporter) {
			reporter.publishEntry(new ReportingEntry(new HashMap<>()));
		}

		@Test
		void succeedingTest(TestReporter reporter) {
			reporter.publishEntry(new ReportingEntry(new HashMap<>()));
		}

	}

}

@@ -404,16 +404,74 @@
 Equals;%0A
+import static org.junit.gen5.api.Assertions.expectThrows;%0A
 import s
@@ -843,16 +843,83 @@
 gEntry;%0A
+import org.junit.gen5.commons.util.PreconditionViolationException;%0A
 import o
@@ -1309,33 +1309,33 @@
 %0A%09%09assertEquals(
-1
+2
 L, eventRecorder
@@ -1393,17 +1393,17 @@
 tEquals(
-1
+2
 L, event
@@ -1553,9 +1553,9 @@
 als(
-3
+5
 L, e
@@ -2037,14 +2037,283 @@
 );%0A%09%09%7D%0A%0A
+        @Test%0A        @SuppressWarnings(%22ThrowableResultOfMethodCallIgnored%22)%0A        void testWithNullReportData(TestReporter reporter) %7B%0A            expectThrows(PreconditionViolationException.class, () -%3E reporter.publishEntry(new ReportingEntry(null)));%0A        %7D%0A%0A
 %09%7D%0A%0A%7D%0A

verify null-safety with test