<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.console;

import static org.junit.gen5.console.ColoredPrintingTestListener.Color.*;

import java.io.PrintStream;

import org.junit.gen5.engine.TestDescriptor;
import org.junit.gen5.engine.TestExecutionListener;
import org.junit.gen5.engine.TestPlanExecutionListener;

/**
 * @author <NAME>
 * @author <NAME>
 * @since 5.0
 */
public class ColoredPrintingTestListener implements TestPlanExecutionListener, TestExecutionListener {

	private static final String ANSI_RESET = "\u001B[0m";

	private final PrintStream out;


	public ColoredPrintingTestListener(PrintStream out) {
		this.out = out;
	}

	@Override
	public void testPlanExecutionStarted(int numberOfStaticTests) {
		out.printf("Test execution started. Number of static tests: %d%n", numberOfStaticTests);
	}

	@Override
	public void testPlanExecutionPaused() {
		out.println("Test execution paused.");
	}

	@Override
	public void testPlanExecutionRestarted() {
		out.println("Test execution continued.");
	}

	@Override
	public void testPlanExecutionStopped() {
		out.println("Test execution canceled.");
	}

	@Override
	public void testPlanExecutionFinished() {
	}

	@Override
	public void dynamicTestFound(TestDescriptor testDescriptor) {
		printlnTestDescriptor(BLUE, "Test found:", testDescriptor);
	}

	@Override
	public void testStarted(TestDescriptor testDescriptor) {
		printlnTestDescriptor(BLACK, "Test started:", testDescriptor);
	}

	@Override
	public void testSkipped(TestDescriptor testDescriptor, Throwable t) {
		printlnTestDescriptor(YELLOW, "Test skipped:", testDescriptor);
		printlnException(YELLOW, t);
	}

	@Override
	public void testAborted(TestDescriptor testDescriptor, Throwable t) {
		printlnTestDescriptor(YELLOW, "Test aborted:", testDescriptor);
		printlnException(YELLOW, t);
	}

	@Override
	public void testFailed(TestDescriptor testDescriptor, Throwable t) {
		printlnTestDescriptor(RED, "Test failed:", testDescriptor);
		printlnException(RED, t);
	}

	@Override
	public void testSucceeded(TestDescriptor testDescriptor) {
		printlnTestDescriptor(GREEN, "Test succeeded:", testDescriptor);
	}

	private void printlnTestDescriptor(Color color, String message, TestDescriptor testDescriptor) {
		println(color, "%-15s   %s [%s]", message, testDescriptor.getDisplayName(), testDescriptor.getUniqueId());
	}

	private void printlnException(Color color, Throwable throwable) {
		println(color, "                  => Exception:   %s", throwable.getLocalizedMessage());
	}

	void println(Color color, String format, Object... args) {
		out.print(color.ansiCode);
		out.format(format, args);
		out.println(ANSI_RESET);
	}


	enum Color {
		BLACK("\u001B[30m"), //
		RED("\u001B[31m"), //
		GREEN("\u001B[32m"), //
		YELLOW("\u001B[33m"), //
		BLUE("\u001B[34m"), //<commit_msg>Output test started without a color<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.console;

import static org.junit.gen5.console.ColoredPrintingTestListener.Color.*;

import java.io.PrintStream;

import org.junit.gen5.engine.TestDescriptor;
import org.junit.gen5.engine.TestExecutionListener;
import org.junit.gen5.engine.TestPlanExecutionListener;

/**
 * @author <NAME>
 * @author <NAME>
 * @since 5.0
 */
public class ColoredPrintingTestListener implements TestPlanExecutionListener, TestExecutionListener {

	private final PrintStream out;


	public ColoredPrintingTestListener(PrintStream out) {
		this.out = out;
	}

	@Override
	public void testPlanExecutionStarted(int numberOfStaticTests) {
		out.printf("Test execution started. Number of static tests: %d%n", numberOfStaticTests);
	}

	@Override
	public void testPlanExecutionPaused() {
		out.println("Test execution paused.");
	}

	@Override
	public void testPlanExecutionRestarted() {
		out.println("Test execution continued.");
	}

	@Override
	public void testPlanExecutionStopped() {
		out.println("Test execution canceled.");
	}

	@Override
	public void testPlanExecutionFinished() {
	}

	@Override
	public void dynamicTestFound(TestDescriptor testDescriptor) {
		printlnTestDescriptor(BLUE, "Test found:", testDescriptor);
	}

	@Override
	public void testStarted(TestDescriptor testDescriptor) {
		printlnTestDescriptor(NONE, "Test started:", testDescriptor);
	}

	@Override
	public void testSkipped(TestDescriptor testDescriptor, Throwable t) {
		printlnTestDescriptor(YELLOW, "Test skipped:", testDescriptor);
		printlnException(YELLOW, t);
	}

	@Override
	public void testAborted(TestDescriptor testDescriptor, Throwable t) {
		printlnTestDescriptor(YELLOW, "Test aborted:", testDescriptor);
		printlnException(YELLOW, t);
	}

	@Override
	public void testFailed(TestDescriptor testDescriptor, Throwable t) {
		printlnTestDescriptor(RED, "Test failed:", testDescriptor);
		printlnException(RED, t);
	}

	@Override
	public void testSucceeded(TestDescriptor testDescriptor) {
		printlnTestDescriptor(GREEN, "Test succeeded:", testDescriptor);
	}

	private void printlnTestDescriptor(Color color, String message, TestDescriptor testDescriptor) {
		println(color, "%-15s   %s [%s]", message, testDescriptor.getDisplayName(), testDescriptor.getUniqueId());
	}

	private void printlnException(Color color, Throwable throwable) {
		println(color, "                  => Exception:   %s", throwable.getLocalizedMessage());
	}

	void println(Color color, String format, Object... args) {
		out.print(color.ansiCode);
		out.format(format, args);
		out.println(NONE.ansiCode);
	}


	enum Color {
		NONE("\u001B[0m"), //
		BLACK("\u001B[30m"), //
		RED("\u001B[31m"), //
		GREEN("\u001B[32m"), //
		YELLOW("\u001B[33m"), //
		BLUE("\u001B[34m"), //
{'fraction_non_alphanumeric': 0.1143317230273752, 'fraction_numerical': 0.014814814814814815, 'mean_word_length': 5.137351778656127, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3754812', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1816, 'n_words': 452}