Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 181   Methods: 11
NCLOC: 138   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
CustomInterceptorChainTest.java 50% 96% 100% 95.5%
coverage coverage
 1    package org.jboss.cache.factories;
 2   
 3    import org.jboss.cache.CacheSPI;
 4    import org.jboss.cache.DefaultCacheFactory;
 5    import org.jboss.cache.config.Configuration;
 6    import org.jboss.cache.interceptors.Interceptor;
 7   
 8    import java.util.List;
 9   
 10    /**
 11    * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
 12    */
 13    public class CustomInterceptorChainTest extends InterceptorChainTestBase
 14    {
 15    private CacheSPI cache;
 16   
 17  9 protected void setUp() throws Exception
 18    {
 19  9 Configuration c = new Configuration();
 20  9 cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(c);
 21  9 cache.create();
 22    }
 23   
 24  9 protected void tearDown()
 25    {
 26  9 if (cache != null)
 27    {
 28  9 cache.stop();
 29  9 cache = null;
 30    }
 31    }
 32   
 33  1 public void testChainImmutability()
 34    {
 35  1 try
 36    {
 37  1 cache.getInterceptorChain().add(new TestInterceptor());
 38  0 fail("unsupportedException should have been thrown as the chain obtained from the cache should be immutable");
 39    }
 40    catch (UnsupportedOperationException uoe)
 41    {
 42    // this is expected.
 43    }
 44    }
 45   
 46  1 public void testInjectionAtHead()
 47    {
 48  1 List<Interceptor> interceptors = cache.getInterceptorChain();
 49  1 assertEquals("Expecting 6 interceptors", 7, interceptors.size());
 50  1 assertInterceptorLinkage(interceptors);
 51   
 52  1 Interceptor x = new TestInterceptor();
 53  1 cache.addInterceptor(x, 0);
 54   
 55  1 interceptors = cache.getInterceptorChain();
 56  1 assertEquals("Expecting 7 interceptors", 8, interceptors.size());
 57  1 assertInterceptorLinkage(interceptors);
 58   
 59  1 assertEquals(x, interceptors.get(0));
 60    }
 61   
 62  1 public void testInjectionAtTail()
 63    {
 64  1 List<Interceptor> interceptors = cache.getInterceptorChain();
 65  1 assertEquals("Expecting 6 interceptors", 7, interceptors.size());
 66  1 assertInterceptorLinkage(interceptors);
 67   
 68  1 Interceptor x = new TestInterceptor();
 69  1 cache.addInterceptor(x, 6);
 70   
 71  1 interceptors = cache.getInterceptorChain();
 72  1 assertEquals("Expecting 7 interceptors", 8, interceptors.size());
 73  1 assertInterceptorLinkage(interceptors);
 74   
 75  1 assertEquals(x, interceptors.get(6));
 76    }
 77   
 78  1 public void testInjectionInMiddle()
 79    {
 80  1 List<Interceptor> interceptors = cache.getInterceptorChain();
 81  1 assertEquals("Expecting 6 interceptors", 7, interceptors.size());
 82  1 assertInterceptorLinkage(interceptors);
 83   
 84  1 Interceptor x = new TestInterceptor();
 85  1 cache.addInterceptor(x, 3);
 86   
 87  1 interceptors = cache.getInterceptorChain();
 88  1 assertEquals("Expecting 7 interceptors", 8, interceptors.size());
 89  1 assertInterceptorLinkage(interceptors);
 90   
 91  1 assertEquals(x, interceptors.get(3));
 92    }
 93   
 94  1 public void testInjectionBeyondTail()
 95    {
 96  1 List<Interceptor> interceptors = cache.getInterceptorChain();
 97  1 assertEquals("Expecting 6 interceptors", 7, interceptors.size());
 98  1 assertInterceptorLinkage(interceptors);
 99   
 100  1 Interceptor x = new TestInterceptor();
 101  1 try
 102    {
 103  1 cache.addInterceptor(x, 8);
 104  0 fail("Should throw an exception");
 105    }
 106    catch (IndexOutOfBoundsException e)
 107    {
 108    // expected
 109    }
 110    }
 111   
 112  1 public void testRemoveAtHead()
 113    {
 114  1 List<Interceptor> interceptors = cache.getInterceptorChain();
 115  1 Interceptor afterHead = interceptors.get(1);
 116  1 assertEquals("Expecting 6 interceptors", 7, interceptors.size());
 117  1 assertInterceptorLinkage(interceptors);
 118   
 119  1 cache.removeInterceptor(0);
 120   
 121  1 interceptors = cache.getInterceptorChain();
 122  1 assertEquals("Expecting 5 interceptors", 6, interceptors.size());
 123  1 assertInterceptorLinkage(interceptors);
 124   
 125  1 assertEquals(afterHead, interceptors.get(0));
 126    }
 127   
 128  1 public void testRemoveAtTail()
 129    {
 130  1 List<Interceptor> interceptors = cache.getInterceptorChain();
 131  1 Interceptor beforeTail = interceptors.get(4);
 132  1 assertEquals("Expecting 6 interceptors", 7, interceptors.size());
 133  1 assertInterceptorLinkage(interceptors);
 134   
 135  1 cache.removeInterceptor(5);
 136   
 137  1 interceptors = cache.getInterceptorChain();
 138   
 139  1 System.out.println(interceptors);
 140   
 141  1 assertEquals("Expecting 5 interceptors", 6, interceptors.size());
 142  1 assertInterceptorLinkage(interceptors);
 143   
 144  1 assertEquals(beforeTail, interceptors.get(4));
 145    }
 146   
 147  1 public void testRemoveAtMiddle()
 148    {
 149  1 List<Interceptor> interceptors = cache.getInterceptorChain();
 150  1 assertEquals("Expecting 6 interceptors", 7, interceptors.size());
 151  1 assertInterceptorLinkage(interceptors);
 152   
 153  1 cache.removeInterceptor(3);
 154   
 155  1 interceptors = cache.getInterceptorChain();
 156  1 assertEquals("Expecting 5 interceptors", 6, interceptors.size());
 157  1 assertInterceptorLinkage(interceptors);
 158    }
 159   
 160  1 public void testRemoveBeyondTail()
 161    {
 162  1 List<Interceptor> interceptors = cache.getInterceptorChain();
 163  1 assertEquals("Expecting 6 interceptors", 7, interceptors.size());
 164  1 assertInterceptorLinkage(interceptors);
 165   
 166  1 try
 167    {
 168  1 cache.removeInterceptor(8);
 169  0 fail("Should throw an exception");
 170    }
 171    catch (IndexOutOfBoundsException e)
 172    {
 173    // expected
 174    }
 175    }
 176   
 177   
 178    public static class TestInterceptor extends Interceptor
 179    {
 180    }
 181    }