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

import javax.enterprise.inject.Instance;
import javax.servlet.ServletContext;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.ocelotds.Constants;
import org.slf4j.Logger;
import static org.mockito.Mockito.*;
import static org.assertj.core.api.Assertions.*;

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

	@Mock
	private Logger logger;

	@InjectMocks
	@Spy
	private OcelotConfiguration ocelotConfiguration;
	
	@Mock
	private Instance<String> ocelotConfigurationsStack;

	/**
	 * Test of readConfigFromContext method, of class OcelotConfiguration.
	 */
	@Test
	public void readConfigFromContext() {
		System.out.println("testReadConfigFromContext");
		// given
		ServletContext sc = mock(ServletContext.class);
		// when
		when(sc.getInitParameter(eq(Constants.Options.STACKTRACE_LENGTH))).thenReturn(null).thenReturn("20");
		when(ocelotConfigurationsStack.isUnsatisfied()).thenReturn(true);
		
		// then
		ocelotConfiguration.readStacktraceConfig(sc);
		int result = ocelotConfiguration.getStacktracelength();
		assertThat(result).isEqualTo(50);

		ocelotConfiguration.readStacktraceConfig(sc);
		result = ocelotConfiguration.getStacktracelength();
		assertThat(result).isEqualTo(20);
	}

	/**
	 * Test of readConfigFromContext method, of class OcelotConfiguration.
	 */
	@Test
	public void readConfigFromProducer() {
		System.out.println("testReadConfigFromContext");
		// given
		ServletContext sc = mock(ServletContext.class);
		// when
		when(ocelotConfigurationsStack.isUnsatisfied()).thenReturn(false);
		when(ocelotConfigurationsStack.get()).thenReturn("80");
		
		// then
		ocelotConfiguration.readStacktraceConfig(sc);
		int result = ocelotConfiguration.getStacktracelength();
		assertThat(result).isEqualTo(80);
	}

	/**
	 * Test of getStacktracelength method, of class OcelotConfiguration.
	 */
	@Test
	public void testGetSetStacktracelength() {
		System.out.println("testGetSetStacktracelength");
		int expResult = 50;
		int result = ocelotConfiguration.getStacktracelength();
		assertThat(result).isEqualTo(expResult);
		expResult = 10;
		ocelotConfiguration.setStacktracelength(expResult);
		result = ocelotConfiguration.getStacktracelength();
		assertThat(result).isEqualTo(expResult);
	}
}

@@ -1305,17 +1305,17 @@
 Return(%22
-2
+1
 0%22);%0D%0A%09%09
@@ -1535,17 +1535,17 @@
 EqualTo(
-5
+2
 0);%0D%0A%0D%0A%09
@@ -1674,25 +1674,25 @@
 ).isEqualTo(
-2
+1
 0);%0D%0A%09%7D%0D%0A%0D%0A%09
@@ -2456,9 +2456,9 @@
 t = 
-5
+2
 0;%0D%0A

fix test 2