/* 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.security;

import java.security.Principal;
import org.junit.Test;
import static org.mockito.Mockito.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.ocelotds.Constants;
import org.ocelotds.context.ThreadLocalContextHolder;
import org.slf4j.Logger;

/**
 *
 * @author hhfrancois
 */
@RunWith(MockitoJUnitRunner.class)
public class OcelotPrincipalTest {

	@Mock
	private Logger logger;

	@InjectMocks
	private OcelotPrincipal instance;

	/**
	 * Test of getName method, of class OcelotPrincipal.
	 */
	@Test
	public void testGetName() {
		System.out.println("getName");
		ThreadLocalContextHolder.cleanupThread();
		String result = instance.getName();
		assertThat(result).isEqualTo(Constants.ANONYMOUS);
		String expResult = "username";
		Principal p = mock(Principal.class);
		when(p.getName()).thenReturn(expResult);
		ThreadLocalContextHolder.put(Constants.PRINCIPAL, p);
		result = instance.getName();
		assertThat(result).isEqualTo(expResult);
	}

}

@@ -1320,12 +1320,516 @@
 ult);%0A%09%7D
+%0A%09%0A%09@Test%0A%09public void testToString() %7B%0A%09%09System.out.println(%22toString%22);%0A%09%09ThreadLocalContextHolder.cleanupThread();%0A%09%09String result = instance.toString();%0A%09%09assertThat(result).isEqualTo(%22OcelotPrincipal(%22+Constants.ANONYMOUS+%22)%22);%0A%09%09String expResult = %22username%22;%0A%09%09Principal p = mock(Principal.class);%0A%09%09when(p.getName()).thenReturn(expResult);%0A%09%09ThreadLocalContextHolder.put(Constants.PRINCIPAL, p);%0A%09%09result = instance.toString();%0A%09%09assertThat(result).isEqualTo(%22OcelotPrincipal(%22+expResult+%22)%22);%0A%09%7D
 %0A%0A%7D%0A

use injected principal override toString