/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.ocelotds.context;

import java.lang.reflect.Constructor;
import org.junit.Before;
import org.junit.Test;
import static org.assertj.core.api.Assertions.*;
import org.ocelotds.Constants;

/**
 *
 * @author hhfrancois
 */
public class ThreadLocalContextHolderTest {
	
	private final String EXPECTED = "fr";
	
	@Before
	public void setUp() {
		ThreadLocalContextHolder.put(Constants.PRINCIPAL, EXPECTED);
	}
	
	/**
	 * Test constructor is private
	 * @throws java.lang.InstantiationException
	 * @throws java.lang.IllegalAccessException
	 * @throws java.lang.NoSuchMethodException
	 */
	@Test
	public void testPrivateConstructor() throws InstantiationException, IllegalAccessException, NoSuchMethodException  {
		Constructor<?>[] constructors = ThreadLocalContextHolder.class.getConstructors();
		assertThat(constructors.length).isEqualTo(0);
		Constructor<ThreadLocalContextHolder> constructor = ThreadLocalContextHolder.class.getDeclaredConstructor();
		assertThat(constructor.getModifiers()).isEqualTo(0);
	   ThreadLocalContextHolder.class.newInstance();
	}

	/**
	 * Test constructor is private
	 * @throws java.lang.InstantiationException
	 * @throws java.lang.IllegalAccessException
	 */
	@Test
	public void testPrivateConstructor1() throws InstantiationException, IllegalAccessException  {
	}

	/**
	 * Test of put method, of class ThreadLocalContextHolder.
	 */
	@Test
	public void testPut() {
		System.out.println("put");
		Object result = ThreadLocalContextHolder.get(Constants.PRINCIPAL);
		assertThat(result).isEqualTo(EXPECTED);
		ThreadLocalContextHolder.put(Constants.PRINCIPAL, null);
		result = ThreadLocalContextHolder.get(Constants.PRINCIPAL);
		assertThat(result).isEqualTo(null);
	}

	/**
	 * Test of cleanupThread method, of class ThreadLocalContextHolder.
	 */
	@Test
	public void testCleanupThread() {
		System.out.println("cleanupThread");
		ThreadLocalContextHolder.cleanupThread();
		Object locale = ThreadLocalContextHolder.get(Constants.PRINCIPAL);
		assertThat(locale).isNull();
	}
	
}

@@ -277,34 +277,8 @@
 r;%0D%0A
-import org.junit.Before;%0D%0A
 impo
@@ -475,16 +475,23 @@
 private 
+static 
 final St
@@ -499,129 +499,26 @@
 ing 
-EXPECTED = %22fr%22;%0D%0A%09%0D%0A%09@Before%0D%0A%09public void setUp() %7B%0D%0A%09%09ThreadLocalContextHolder.put(Constants.PRINCIPAL, EXPECTED);%0D%0A%09%7D
+NAME = %22francois%22;
 %0D%0A%09%0D
@@ -1205,233 +1205,296 @@
 est 
-constructor is private%0D%0A%09 * @throws java.lang.InstantiationException%0D%0A%09 * @throws java.lang.IllegalAccessException%0D%0A%09 */%0D%0A%09@Test%0D%0A%09public void testPrivateConstructor1() throws InstantiationException, IllegalAccessException  %7B
+of put method, of class ThreadLocalContextHolder.%0D%0A%09 */%0D%0A%09@Test%0D%0A%09public void testPut() %7B%0D%0A%09%09System.out.println(%22put%22);%0D%0A%09%09ThreadLocalContextHolder.put(Constants.PRINCIPAL, NAME);%0D%0A%09%09Object result = ThreadLocalContextHolder.get(Constants.PRINCIPAL);%0D%0A%09%09assertThat(result).isEqualTo(NAME);
 %0D%0A%09%7D
@@ -1586,34 +1586,41 @@
 public void test
-Pu
+CleanExis
 t() %7B%0D%0A%09%09System.
@@ -1646,171 +1646,580 @@
 %0D%0A%09%09
-Object result = ThreadLocalContextHolder.get(Constants.PRINCIPAL);%0D%0A%09%09assertThat(result).isEqualTo(EXPECTED);%0D%0A%09%09ThreadLocalContextHolder.put(Constants.PRINCIPAL, 
+ThreadLocalContextHolder.put(Constants.PRINCIPAL, NAME);%0D%0A%09%09ThreadLocalContextHolder.put(Constants.PRINCIPAL, null);%0D%0A%09%09Object result = ThreadLocalContextHolder.get(Constants.PRINCIPAL);%0D%0A%09%09assertThat(result).isEqualTo(null);%0D%0A%09%7D%0D%0A%0D%0A%09/**%0D%0A%09 * Test of put method, of class ThreadLocalContextHolder.%0D%0A%09 */%0D%0A%09@Test%0D%0A%09public void testCleanNotExist() %7B%0D%0A%09%09System.out.println(%22put%22);%0D%0A%09%09ThreadLocalContextHolder.put(Constants.PRINCIPAL, NAME);%0D%0A%09%09ThreadLocalContextHolder.put(%22FOO%22, null);%0D%0A%09%09Object result = ThreadLocalContextHolder.get(%22FOO%22);%0D%0A%09%09assertThat(result).isEqualTo(
 null
@@ -2308,38 +2308,40 @@
 sult).isEqualTo(
-null);
+NAME);%09%09
 %0D%0A%09%7D%0D%0A%0D%0A%09/**%0D%0A%09 
@@ -2494,24 +2494,84 @@
 pThread%22);%0D%0A
+%09%09ThreadLocalContextHolder.put(Constants.PRINCIPAL, NAME);%0D%0A
 %09%09ThreadLoca
@@ -2612,22 +2612,22 @@
 %09Object 
-locale
+result
  = Threa
@@ -2690,14 +2690,14 @@
 hat(
-locale
+result
 ).is

improve test