package nl.siegmann.ehcachetag;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;

import junit.framework.Assert;
import nl.siegmann.ehcachetag.cachetagmodifier.CacheTagModifier;
import nl.siegmann.ehcachetag.cachetagmodifier.CacheTagModifierFactory;
import nl.siegmann.ehcachetag.cachetagmodifier.DefaultCacheTagModifierFactory;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

public class EHCacheTagServletContextListenerTest {

	private EHCacheTagServletContextListener testSubject;
	
	@Mock
	private ServletContextEvent servletContextEvent;
	
	@Mock
	private ServletContext servletContext;
	
	@Before
	public void setUp() {
		MockitoAnnotations.initMocks(this);
		this.testSubject = new EHCacheTagServletContextListener();
		Mockito.when(servletContextEvent.getServletContext()).thenReturn(servletContext);
		TestMetaCacheKeyFactory.servletContext = null;
	}
	
	static class TestMetaCacheKeyFactory implements CacheTagModifierFactory {

		public static ServletContext servletContext;
		
		@Override
		public CacheTagModifier getCacheTagModifier(String cacheTagPreProcessorName) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public void init(ServletContext servletContext) {
			TestMetaCacheKeyFactory.servletContext = servletContext;
		}

		@Override
		public void destroy() {
			// TODO Auto-generated method stub
			
		}
		
	}
	@Test
	public void test_defaults() {

		// when
		testSubject.contextInitialized(servletContextEvent);
		
		// then
		Mockito.verify(servletContextEvent).getServletContext();
		Mockito.verify(servletContext).setAttribute(Mockito.eq(EHCacheTagConstants.MODIFIER_FACTORY_ATTRIBUTE), Mockito.any(DefaultCacheTagModifierFactory.class));
		
	}

	@Test
	public void test_custom_CacheKeyMetaFactory() {
		// given
		Mockito.when(servletContext.getInitParameter("ehcachetag.cacheKeyMetaFactoryClass")).thenReturn(TestMetaCacheKeyFactory.class.getName());
		
		// when
		testSubject.contextInitialized(servletContextEvent);
		
		// then
		Mockito.verify(servletContextEvent).getServletContext();
		Mockito.verify(servletContext).setAttribute(Mockito.eq(EHCacheTagConstants.MODIFIER_FACTORY_ATTRIBUTE), Mockito.any(DefaultCacheTagModifierFactory.class));
		Assert.assertNotNull(TestMetaCacheKeyFactory.servletContext);
	}
}

@@ -26,16 +26,46 @@
 hetag;%0A%0A
+import java.util.Collection;%0A%0A
 import j
@@ -1502,16 +1502,106 @@
 %0A%09%09%09%0A%09%09%7D
+%0A%0A%09%09@Override%0A%09%09public Collection%3CString%3E getCacheTagModifierNames() %7B%0A%09%09%09return null;%0A%09%09%7D
 %0A%09%09%0A%09%7D%0A%09
@@ -2058,45 +2058,56 @@
 ter(
-%22ehcachetag.cacheKeyMetaFactoryClass%22
+EHCacheTagConstants.MODIFIER_FACTORY_CLASS_PARAM
 )).t

fix unit test