<commit_before>/*
 * 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 com.example.timing;

import static org.junit.gen5.api.extension.ExtensionPointRegistry.Position.INNERMOST;

import java.lang.reflect.Method;

import org.junit.gen5.api.extension.AfterEachExtensionPoint;
import org.junit.gen5.api.extension.BeforeEachExtensionPoint;
import org.junit.gen5.api.extension.ExtensionPointRegistry;
import org.junit.gen5.api.extension.ExtensionRegistrar;
import org.junit.gen5.api.extension.TestExtensionContext;

/**
 * Simple extension that <em>times</em> the execution of test methods and
 * prints the results to {@link System#out}.
 *
 * @since 5.0
 */
public class TimingExtension implements ExtensionRegistrar {

	private static final String TIMING_KEY_PREFIX = "TIMING:";

	@Override
	public void registerExtensions(ExtensionPointRegistry registry) {
		registry.register(this::beforeEach, BeforeEachExtensionPoint.class, INNERMOST);
		registry.register(this::afterEach, AfterEachExtensionPoint.class, INNERMOST);
	}

	private void beforeEach(TestExtensionContext context) throws Exception {
		Method testMethod = context.getTestMethod();
		context.putAttribute(createKey(testMethod), System.currentTimeMillis());
	}

	private void afterEach(TestExtensionContext context) throws Exception {
		Method testMethod = context.getTestMethod();
		String key = createKey(testMethod);
		long start = (long) context.getAttribute(key);
		long end = System.currentTimeMillis();

		System.out.println(String.format("Method [%s] took %s ms", testMethod.getName(), (end - start)));
		context.removeAttribute(key);
	}

	private String createKey(Method testMethod) {
		return TIMING_KEY_PREFIX + testMethod;
	}

}<commit_msg>Refactor TimingExtension to use key/namespace support in ExtensionContext<commit_after>/*
 * 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 com.example.timing;

import static org.junit.gen5.api.extension.ExtensionPointRegistry.Position.INNERMOST;

import java.lang.reflect.Method;

import org.junit.gen5.api.extension.AfterEachExtensionPoint;
import org.junit.gen5.api.extension.BeforeEachExtensionPoint;
import org.junit.gen5.api.extension.ExtensionPointRegistry;
import org.junit.gen5.api.extension.ExtensionRegistrar;
import org.junit.gen5.api.extension.TestExtensionContext;

/**
 * Simple extension that <em>times</em> the execution of test methods and
 * prints the results to {@link System#out}.
 *
 * @since 5.0
 */
public class TimingExtension implements ExtensionRegistrar {

	private final String namespace = getClass().getName();

	@Override
	public void registerExtensions(ExtensionPointRegistry registry) {
		registry.register(this::beforeEach, BeforeEachExtensionPoint.class, INNERMOST);
		registry.register(this::afterEach, AfterEachExtensionPoint.class, INNERMOST);
	}

	private void beforeEach(TestExtensionContext context) throws Exception {
		context.put(context.getTestMethod(), System.currentTimeMillis(), namespace);
	}

	private void afterEach(TestExtensionContext context) throws Exception {
		Method testMethod = context.getTestMethod();
		long start = (long) context.remove(testMethod, namespace);
		long duration = System.currentTimeMillis() - start;

		System.out.println(String.format("Method [%s] took %s ms.", testMethod, duration));
	}

}
{'fraction_non_alphanumeric': 0.0997904662126768, 'fraction_numerical': 0.010476689366160294, 'mean_word_length': 5.561855670103093, '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': '5452905', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1049, 'n_words': 276}