// Path: ehcachetag/src/main/java/nl/siegmann/ehcachetag/CacheTag.java
// static final class ModifierNotFoundException extends Exception {
// 
// 	private static final long serialVersionUID = 4535024464306691589L;
// 
// 	public ModifierNotFoundException(String message) {
// 		super(message);
// 	}
// }
// 
// Path: ehcachetag/src/main/java/nl/siegmann/ehcachetag/cachetagmodifier/CacheTagModifier.java
// public interface CacheTagModifier {
// 
// 	/**
// 	 * CacheTagInterceptor that does not do anything.
// 	 * 
// 	 */
// 	CacheTagModifier NULL_CACHETAG_MODIFIER = new CacheTagModifier() {
// 		
// 		@Override
// 		public void init(ServletContext servletContext) {
// 		}
// 		
// 		@Override
// 		public void beforeLookup(CacheTag cacheTag, JspContext jspContext) {
// 		}
// 		
// 		@Override
// 		public String afterRetrieval(CacheTag cacheTag, JspContext jspContext,
// 				String content) {
// 			return content;
// 		}
// 		
// 		@Override
// 		public void destroy() {
// 		}
// 
// 		@Override
// 		public String beforeUpdate(CacheTag cacheTag, JspContext jspContext,
// 				String content) {
// 			return content;
// 		}
// 
// 	};
// 	
// 	/**
// 	 * Called once on Application startup.
// 	 * 
// 	 * @param properties
// 	 */
// 	void init(ServletContext servletContext);
// 	
// 	/**
// 	 * Called before Cache lookup.
// 	 * 
// 	 * Will be called by different threads concurrently.
// 	 */
// 	void beforeLookup(CacheTag cacheTag, JspContext jspContext);
// 	
// 	/**
// 	 * Called before updating the cache with the given content.
// 	 * 
// 	 * @param cacheTag
// 	 * @param jspContext
// 	 * @param content the content that will be stored in the cache
// 	 * @return the content to store in the cache.
// 	 */
// 	String beforeUpdate(CacheTag cacheTag, JspContext jspContext, String content);
// 	
// 	
// 	/**
// 	 * Called after retrieving content from the cache but before it's written to the output.
// 	 * 
// 	 * @param cacheTag
// 	 * @param jspContext
// 	 * @param content the content that will be sent back to the client
// 	 * @return The content to send back to the client
// 	 */
// 	String afterRetrieval(CacheTag cacheTag, JspContext jspContext, String content);
// 
// 	/**
// 	 * Called on Application shutdown.
// 	 */
// 	void destroy();
// }
// 
// Path: ehcachetag/src/main/java/nl/siegmann/ehcachetag/cachetagmodifier/CacheTagModifierFactory.java
// public interface CacheTagModifierFactory {
// 
// 	/**
// 	 * Called once after application is initialized.
// 	 * 
// 	 * @param servletContext
// 	 */
// 	void init(ServletContext servletContext);
// 
// 	/**
// 	 * The names of the available cacheTagModifiers
// 	 * 
// 	 * @return The names of the available cacheTagModifiers
// 	 */
// 	Collection<String> getCacheTagModifierNames();
// 
// 	/**
// 	 * Gets the cacheTagModifier with the given name, null if not found.
// 	 * 
// 	 * @param cacheTagModifierName name of the CacheTagModifier we're looking for.
// 	 * 
// 	 * @return the CacheTagModifier with the given name, null if not found.
// 	 */
// 	CacheTagModifier getCacheTagModifier(String cacheTagModifierName);
// 
// 	/**
// 	 * Called once on application destroy.
// 	 * 
// 	 */
// 	void destroy();
// }


import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import nl.siegmann.ehcachetag.CacheTag.ModifierNotFoundException;
import nl.siegmann.ehcachetag.cachetagmodifier.CacheTagModifier;
import nl.siegmann.ehcachetag.cachetagmodifier.CacheTagModifierFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

	/**
	 * Test the case where the before cache lookup causes an exception.
	 * @throws Exception 
	 */
	@Test
	public void doStartTag_before_lookup_excepion() throws Exception {
		// given
		Mockito.doThrow(new Exception()).when(testSubject).doBeforeLookup();
		
		// when
		int startTagReturn = testSubject.doStartTag();
		
		// then
		Assert.assertEquals(1, startTagReturn);
		verifyCleanup();
	}
	
	
	/**
	 * Test the behaviour when writing the result to the outputstream causes an IOException.
	 * @throws IOException 
	 * @throws JspException 
	 */
	@Test(expected = JspException.class)
	public void doStartTag_exception_writing_cached_content() throws IOException, JspException {
		// given
		testSubject.setKey("mykey");
		testSubject.setCache("ehcachetag");
		Mockito.doReturn("foo").when(testSubject).getCachedBodyContent("ehcachetag", "mykey");
// Path: ehcachetag/src/main/java/nl/siegmann/ehcachetag/CacheTag.java
// static final class ModifierNotFoundException extends Exception {
// 
// 	private static final long serialVersionUID = 4535024464306691589L;
// 
// 	public ModifierNotFoundException(String message) {
// 		super(message);
// 	}
// }
// 
// Path: ehcachetag/src/main/java/nl/siegmann/ehcachetag/cachetagmodifier/CacheTagModifier.java
// public interface CacheTagModifier {
// 
// 	/**
// 	 * CacheTagInterceptor that does not do anything.
// 	 * 
// 	 */
// 	CacheTagModifier NULL_CACHETAG_MODIFIER = new CacheTagModifier() {
// 		
// 		@Override
// 		public void init(ServletContext servletContext) {
// 		}
// 		
// 		@Override
// 		public void beforeLookup(CacheTag cacheTag, JspContext jspContext) {
// 		}
// 		
// 		@Override
// 		public String afterRetrieval(CacheTag cacheTag, JspContext jspContext,
// 				String content) {
// 			return content;
// 		}
// 		
// 		@Override
// 		public void destroy() {
// 		}
// 
// 		@Override
// 		public String beforeUpdate(CacheTag cacheTag, JspContext jspContext,
// 				String content) {
// 			return content;
// 		}
// 
// 	};
// 	
// 	/**
// 	 * Called once on Application startup.
// 	 * 
// 	 * @param properties
// 	 */
// 	void init(ServletContext servletContext);
// 	
// 	/**
// 	 * Called before Cache lookup.
// 	 * 
// 	 * Will be called by different threads concurrently.
// 	 */
// 	void beforeLookup(CacheTag cacheTag, JspContext jspContext);
// 	
// 	/**
// 	 * Called before updating the cache with the given content.
// 	 * 
// 	 * @param cacheTag
// 	 * @param jspContext
// 	 * @param content the content that will be stored in the cache
// 	 * @return the content to store in the cache.
// 	 */
// 	String beforeUpdate(CacheTag cacheTag, JspContext jspContext, String content);
// 	
// 	
// 	/**
// 	 * Called after retrieving content from the cache but before it's written to the output.
// 	 * 
// 	 * @param cacheTag
// 	 * @param jspContext
// 	 * @param content the content that will be sent back to the client
// 	 * @return The content to send back to the client
// 	 */
// 	String afterRetrieval(CacheTag cacheTag, JspContext jspContext, String content);
// 
// 	/**
// 	 * Called on Application shutdown.
// 	 */
// 	void destroy();
// }
// 
// Path: ehcachetag/src/main/java/nl/siegmann/ehcachetag/cachetagmodifier/CacheTagModifierFactory.java
// public interface CacheTagModifierFactory {
// 
// 	/**
// 	 * Called once after application is initialized.
// 	 * 
// 	 * @param servletContext
// 	 */
// 	void init(ServletContext servletContext);
// 
// 	/**
// 	 * The names of the available cacheTagModifiers
// 	 * 
// 	 * @return The names of the available cacheTagModifiers
// 	 */
// 	Collection<String> getCacheTagModifierNames();
// 
// 	/**
// 	 * Gets the cacheTagModifier with the given name, null if not found.
// 	 * 
// 	 * @param cacheTagModifierName name of the CacheTagModifier we're looking for.
// 	 * 
// 	 * @return the CacheTagModifier with the given name, null if not found.
// 	 */
// 	CacheTagModifier getCacheTagModifier(String cacheTagModifierName);
// 
// 	/**
// 	 * Called once on application destroy.
// 	 * 
// 	 */
// 	void destroy();
// }


// Path: ehcachetag/src/test/java/nl/siegmann/ehcachetag/CacheTagTest.java
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import nl.siegmann.ehcachetag.CacheTag.ModifierNotFoundException;
import nl.siegmann.ehcachetag.cachetagmodifier.CacheTagModifier;
import nl.siegmann.ehcachetag.cachetagmodifier.CacheTagModifierFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;


	/**
	 * Test the case where the before cache lookup causes an exception.
	 * @throws Exception 
	 */
	@Test
	public void doStartTag_before_lookup_excepion() throws Exception {
		// given
		Mockito.doThrow(new Exception()).when(testSubject).doBeforeLookup();
		
		// when
		int startTagReturn = testSubject.doStartTag();
		
		// then
		Assert.assertEquals(1, startTagReturn);
		verifyCleanup();
	}
	
	
	/**
	 * Test the behaviour when writing the result to the outputstream causes an IOException.
	 * @throws IOException 
	 * @throws JspException 
	 */
	@Test(expected = JspException.class)
	public void doStartTag_exception_writing_cached_content() throws IOException, JspException {
		// given
		testSubject.setKey("mykey");
		testSubject.setCache("ehcachetag");
		Mockito.doReturn("foo").when(testSubject).getCachedBodyContent("ehcachetag", "mykey");
		Mockito.doThrow(new IOException()).when(jspWriter).write(Mockito.anyString());