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());
	}

}

@@ -68,35 +68,29 @@
 ort 
-lombok.extern.slf4j.Slf4j;%0A
+org.junit.AfterClass;
 %0Aimp
@@ -99,34 +99,30 @@
 t org.junit.
-AfterClass
+Before
 ;%0Aimport org
@@ -205,16 +205,90 @@
 ception;
+%0Aimport org.mockito.MockitoAnnotations;%0A%0Aimport lombok.extern.slf4j.Slf4j;
 %0A%0A/**%0A *
@@ -721,16 +721,141 @@
 l%3C%3E();%0A%0A
+%09/**%0A%09 * Initialize mocks of this class.%0A%09 */%0A%09@Before%0A%09public void injectMock() %7B%0A%09%09MockitoAnnotations.initMocks(this);%0A%09%7D%0A%0A
 %09/**%0A%09 *
@@ -1291,17 +1291,24 @@
 utions%22,
- 
+%0A%09%09%09%09%09%09%09
 new Ille
@@ -1325,24 +1325,16 @@
 ception(
-%0A%09%09%09%09%09%09%09
 %22Somethi

Add MockitoAnnotations#initMocks