<commit_before>package org.ligoj.bootstrap;

import java.security.Permission;

import lombok.extern.slf4j.Slf4j;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.ExpectedException;

/**
 * Common test class.
 */
@Slf4j
public class AbstractTest { // NOPMD NOSONAR
	protected static final int MOCK_PORT = 8120;

	/**
	 * Rule manager for exception.
	 */
	@Rule
	// CHECKSTYLE:OFF -- expected by JUnit
	public ExpectedException thrown = ExpectedException.none();
	// CHECKSTYLE:ON

	/**
	 * Original security manager.
	 */
	protected static final ThreadLocal<SecurityManager> SECURITY_MANAGER_THREAD = new ThreadLocal<>();

	/**
	 * Install a hook to prevent {@link System#exit(int)} to be executed.
	 */
	@BeforeClass
	public static void forbidSystemExitCall() {
		SECURITY_MANAGER_THREAD.set(new SecurityManager() {
			@Override
			public void checkPermission(final Permission permission) {
				if (permission.getName().startsWith("exitVM") && !"-local".equals(System.getProperty("app-env", "-local"))) {
					log.error("Something called exit within test executions", new IllegalStateException(
							"Something called exit within test executions"));
				}
			}
		});
		System.setSecurityManager(SECURITY_MANAGER_THREAD.get());
	}

	/**
	 * Restore previous security manager replaced by the one installed by {@link #forbidSystemExitCall()}.
	 */
	@AfterClass
	public static void restoreSystemExitCall() {
		System.setSecurityManager(SECURITY_MANAGER_THREAD.get());
	}

}<commit_msg>Add MockitoAnnotations#initMocks <commit_after>package org.ligoj.bootstrap;

import java.security.Permission;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.mockito.MockitoAnnotations;

import lombok.extern.slf4j.Slf4j;

/**
 * Common test class.
 */
@Slf4j
public class AbstractTest { // NOPMD NOSONAR
	protected static final int MOCK_PORT = 8120;

	/**
	 * Rule manager for exception.
	 */
	@Rule
	// CHECKSTYLE:OFF -- expected by JUnit
	public ExpectedException thrown = ExpectedException.none();
	// CHECKSTYLE:ON

	/**
	 * Original security manager.
	 */
	protected static final ThreadLocal<SecurityManager> SECURITY_MANAGER_THREAD = new ThreadLocal<>();

	/**
	 * Initialize mocks of this class.
	 */
	@Before
	public void injectMock() {
		MockitoAnnotations.initMocks(this);
	}

	/**
	 * Install a hook to prevent {@link System#exit(int)} to be executed.
	 */
	@BeforeClass
	public static void forbidSystemExitCall() {
		SECURITY_MANAGER_THREAD.set(new SecurityManager() {
			@Override
			public void checkPermission(final Permission permission) {
				if (permission.getName().startsWith("exitVM") && !"-local".equals(System.getProperty("app-env", "-local"))) {
					log.error("Something called exit within test executions",
							new IllegalStateException("Something called exit within test executions"));
				}
			}
		});
		System.setSecurityManager(SECURITY_MANAGER_THREAD.get());
	}

	/**
	 * Restore previous security manager replaced by the one installed by {@link #forbidSystemExitCall()}.
	 */
	@AfterClass
	public static void restoreSystemExitCall() {
		System.setSecurityManager(SECURITY_MANAGER_THREAD.get());
	}

}
{'fraction_non_alphanumeric': 0.11709245742092457, 'fraction_numerical': 0.004257907542579075, 'mean_word_length': 4.4816666666666665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6274536', 'n_tokens_mistral': 1078, 'n_tokens_neox': 982, 'n_words': 241}