<commit_before>/*
 * Copyright 2015 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 java.util.Arrays.asList;
import static org.junit.gen5.api.Assertions.assertEquals;
import static org.junit.gen5.engine.TestPlanSpecification.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Assert;
import org.junit.gen5.api.AfterAll;
import org.junit.gen5.api.BeforeAll;
import org.junit.gen5.api.Test;
import org.junit.gen5.api.extension.AfterAllExtensionPoint;
import org.junit.gen5.api.extension.AfterEachExtensionPoint;
import org.junit.gen5.api.extension.BeforeAllExtensionPoint;
import org.junit.gen5.api.extension.BeforeEachExtensionPoint;
import org.junit.gen5.api.extension.ContainerExtensionContext;
import org.junit.gen5.api.extension.ExtendWith;
import org.junit.gen5.api.extension.ExtensionRegistrar;
import org.junit.gen5.api.extension.ExtensionRegistry;
import org.junit.gen5.api.extension.TestExtensionContext;
import org.junit.gen5.engine.TestPlanSpecification;

/**
 * Integration tests that verify support of {@link BeforeAll}, {@link AfterAll}, and {@link BeforeAllExtensionPoint} in
 * the {@link JUnit5TestEngine}.
 *
 * @since 5.0
 */
public class ClassLevelCallbackTests extends AbstractJUnit5TestEngineTestCase {

	@org.junit.Test
	public void beforeAllAndAfterAllCallbacks() {
		TestPlanSpecification spec = build(forClass(InstancePerMethodTestCase.class));

		TrackingEngineExecutionListener listener = executeTests(spec, 3);

		Assert.assertEquals("# tests started", 2, listener.testStartedCount.get());
		Assert.assertEquals("# tests succeeded", 2, listener.testSucceededCount.get());

		// @formatter:off
		assertEquals(asList(
			"outermostBefore",
				"fooBeforeAll",
				"barBeforeAll",
					"beforeAllMethod",
						"innermostBefore",
							"firstTest",
							"secondTest",
						"innermostAfter",
					"afterAllMethod",
				"barAfterAll",
				"fooAfterAll",
			"outermostAfter"
			), callSequence, "wrong call sequence");
		// @formatter:on
	}

	// -------------------------------------------------------------------

	private static List<String> callSequence = new ArrayList<>();

	@ExtendWith({ FooClassLevelCallbacks.class, BarClassLevelCallbacks.class, InnermostAndOutermost.class })
	private static class InstancePerMethodTestCase {

		@BeforeAll
		static void beforeAll() {
			callSequence.add("beforeAllMethod");
		}

		@AfterAll
		static void afterAll() {
			callSequence.add("afterAllMethod");
		}

		@Test
		void firstTest() {
			callSequence.add("firstTest");
		}

		@Test
		void secondTest() {
			callSequence.add("secondTest");

		}
	}

	private static class InnermostAndOutermost implements ExtensionRegistrar {

		@Override
		public void registerExtensions(ExtensionRegistry registry) {
			registry.register(this::innermostBefore, BeforeAllExtensionPoint.class, Position.INNERMOST);
			registry.register(this::innermostAfter, AfterAllExtensionPoint.class, Position.INNERMOST);
			registry.register(this::outermostBefore, BeforeAllExtensionPoint.class, Position.OUTERMOST);
			registry.register(this::outermostAfter, AfterAllExtensionPoint.class, Position.OUTERMOST);
		}

		private void outermostBefore(ContainerExtensionContext context) {
			callSequence.add("outermostBefore");
		}

		private void innermostBefore(ContainerExtensionContext context) {
			callSequence.add("innermostBefore");
		}

		private void outermostAfter(ContainerExtensionContext context) {
			callSequence.add("outermostAfter");
		}<commit_msg>Fixed flickering test.<commit_after>/*
 * Copyright 2015 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 java.util.Arrays.asList;
import static org.junit.gen5.api.Assertions.assertEquals;
import static org.junit.gen5.engine.TestPlanSpecification.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Assert;
import org.junit.gen5.api.AfterAll;
import org.junit.gen5.api.BeforeAll;
import org.junit.gen5.api.Test;
import org.junit.gen5.api.extension.AfterAllExtensionPoint;
import org.junit.gen5.api.extension.AfterEachExtensionPoint;
import org.junit.gen5.api.extension.BeforeAllExtensionPoint;
import org.junit.gen5.api.extension.BeforeEachExtensionPoint;
import org.junit.gen5.api.extension.ContainerExtensionContext;
import org.junit.gen5.api.extension.ExtendWith;
import org.junit.gen5.api.extension.ExtensionRegistrar;
import org.junit.gen5.api.extension.ExtensionRegistry;
import org.junit.gen5.api.extension.TestExtensionContext;
import org.junit.gen5.engine.TestPlanSpecification;

/**
 * Integration tests that verify support of {@link BeforeAll}, {@link AfterAll}, and {@link BeforeAllExtensionPoint} in
 * the {@link JUnit5TestEngine}.
 *
 * @since 5.0
 */
public class ClassLevelCallbackTests extends AbstractJUnit5TestEngineTestCase {

	@org.junit.Test
	public void beforeAllAndAfterAllCallbacks() {
		TestPlanSpecification spec = build(forClass(InstancePerMethodTestCase.class));

		TrackingEngineExecutionListener listener = executeTests(spec, 2);

		Assert.assertEquals("# tests started", 1, listener.testStartedCount.get());
		Assert.assertEquals("# tests succeeded", 1, listener.testSucceededCount.get());

		// @formatter:off
		assertEquals(asList(
			"outermostBefore",
				"fooBeforeAll",
				"barBeforeAll",
					"beforeAllMethod",
						"innermostBefore",
							"firstTest",
						"innermostAfter",
					"afterAllMethod",
				"barAfterAll",
				"fooAfterAll",
			"outermostAfter"
			), callSequence, "wrong call sequence");
		// @formatter:on
	}

	// -------------------------------------------------------------------

	private static List<String> callSequence = new ArrayList<>();

	@ExtendWith({ FooClassLevelCallbacks.class, BarClassLevelCallbacks.class, InnermostAndOutermost.class })
	private static class InstancePerMethodTestCase {

		@BeforeAll
		static void beforeAll() {
			callSequence.add("beforeAllMethod");
		}

		@AfterAll
		static void afterAll() {
			callSequence.add("afterAllMethod");
		}

		@Test
		void firstTest() {
			callSequence.add("firstTest");
		}

	}

	private static class InnermostAndOutermost implements ExtensionRegistrar {

		@Override
		public void registerExtensions(ExtensionRegistry registry) {
			registry.register(this::innermostBefore, BeforeAllExtensionPoint.class, Position.INNERMOST);
			registry.register(this::innermostAfter, AfterAllExtensionPoint.class, Position.INNERMOST);
			registry.register(this::outermostBefore, BeforeAllExtensionPoint.class, Position.OUTERMOST);
			registry.register(this::outermostAfter, AfterAllExtensionPoint.class, Position.OUTERMOST);
		}

		private void outermostBefore(ContainerExtensionContext context) {
			callSequence.add("outermostBefore");
		}

		private void innermostBefore(ContainerExtensionContext context) {
			callSequence.add("innermostBefore");
		}

		private void outermostAfter(ContainerExtensionContext context) {
			callSequence.add("outermostAfter");
		}
{'fraction_non_alphanumeric': 0.12262128115786652, 'fraction_numerical': 0.008576789064593943, 'mean_word_length': 4.762934362934363, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '537535', 'n_tokens_mistral': 2356, 'n_tokens_neox': 2086, 'n_words': 427}