Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 346   Methods: 31
NCLOC: 294   Classes: 15
 
 Source file Conditionals Statements Methods TOTAL
AnnotationsTest.java - 85.1% 51.6% 75.2%
coverage coverage
 1    package org.jboss.cache.notifications;
 2   
 3    import junit.framework.TestCase;
 4    import org.jboss.cache.Cache;
 5    import org.jboss.cache.DefaultCacheFactory;
 6    import org.jboss.cache.notifications.annotation.CacheListener;
 7    import org.jboss.cache.notifications.annotation.CacheStarted;
 8    import org.jboss.cache.notifications.annotation.CacheStopped;
 9    import org.jboss.cache.notifications.annotation.NodeMoved;
 10    import org.jboss.cache.notifications.event.Event;
 11    import org.jboss.cache.notifications.event.NodeMovedEvent;
 12   
 13    import java.util.List;
 14   
 15    /**
 16    * Tests both correct and incorrect annotations for listeners
 17    *
 18    * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
 19    * @since 2.0.0
 20    */
 21    public class AnnotationsTest extends TestCase
 22    {
 23    private Notifier n;
 24   
 25  14 protected void setUp()
 26    {
 27  14 Cache c = DefaultCacheFactory.getInstance().createCache(false);
 28  14 n = new Notifier(c);
 29    }
 30   
 31  1 public void testControl()
 32    {
 33  1 Object l = new TestControlListener();
 34  1 n.addCacheListener(l);
 35  1 assertEquals(1, n.getCacheListeners().size());
 36    }
 37   
 38  1 public void testCacheListenerNoMethods()
 39    {
 40  1 Object l = new TestCacheListenerNoMethodsListener();
 41  1 n.addCacheListener(l);
 42  1 assertEquals("Hello", l.toString());
 43  1 assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty()); // since the valid listener has no methods to listen
 44    }
 45   
 46  1 public void testNonAnnotatedListener()
 47    {
 48  1 Object l = new TestNonAnnotatedListener();
 49  1 try
 50    {
 51  1 n.addCacheListener(l);
 52  0 fail("Should not accept an un-annotated cache listener");
 53    }
 54    catch (IncorrectCacheListenerException icle)
 55    {
 56    // expected
 57    }
 58  1 assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
 59    }
 60   
 61  1 public void testNonPublicListener()
 62    {
 63  1 Object l = new TestNonPublicListener();
 64  1 try
 65    {
 66  1 n.addCacheListener(l);
 67  0 fail("Should not accept a private callback class");
 68    }
 69    catch (IncorrectCacheListenerException icle)
 70    {
 71    // expected
 72    }
 73  1 assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
 74    }
 75   
 76  1 public void testNonPublicListenerMethod()
 77    {
 78  1 Object l = new TestNonPublicListenerMethodListener();
 79  1 n.addCacheListener(l);
 80   
 81    // should not fail, should just not register anything
 82   
 83  1 assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
 84    }
 85   
 86  1 public void testNonVoidReturnTypeMethod()
 87    {
 88  1 Object l = new TestNonVoidReturnTypeMethodListener();
 89  1 try
 90    {
 91  1 n.addCacheListener(l);
 92  0 fail("Should not accept a listener method with a return type");
 93    }
 94    catch (IncorrectCacheListenerException icle)
 95    {
 96    // expected
 97    }
 98  1 assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
 99    }
 100   
 101   
 102  1 public void testIncorrectMethodSignature1()
 103    {
 104  1 Object l = new TestIncorrectMethodSignature1Listener();
 105  1 try
 106    {
 107  1 n.addCacheListener(l);
 108  0 fail("Should not accept a cache listener with a bad method signature");
 109    }
 110    catch (IncorrectCacheListenerException icle)
 111    {
 112    // expected
 113    }
 114  1 assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
 115    }
 116   
 117  1 public void testIncorrectMethodSignature2()
 118    {
 119  1 Object l = new TestIncorrectMethodSignature2Listener();
 120  1 try
 121    {
 122  1 n.addCacheListener(l);
 123  0 fail("Should not accept a cache listener with a bad method signature");
 124    }
 125    catch (IncorrectCacheListenerException icle)
 126    {
 127    // expected
 128    }
 129  1 assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
 130    }
 131   
 132  1 public void testIncorrectMethodSignature3()
 133    {
 134  1 Object l = new TestIncorrectMethodSignature3Listener();
 135  1 try
 136    {
 137  1 n.addCacheListener(l);
 138  0 fail("Should not accept a cache listener with a bad method signature");
 139    }
 140    catch (IncorrectCacheListenerException icle)
 141    {
 142    // expected
 143    }
 144  1 assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
 145    }
 146   
 147  1 public void testUnassignableMethodSignature()
 148    {
 149  1 Object l = new TestUnassignableMethodSignatureListener();
 150  1 try
 151    {
 152  1 n.addCacheListener(l);
 153  0 fail("Should not accept a cache listener with a bad method signature");
 154    }
 155    catch (IncorrectCacheListenerException icle)
 156    {
 157    // expected
 158    }
 159  1 assertTrue("No listeners should be registered.", n.getCacheListeners().isEmpty());
 160    }
 161   
 162  1 public void testPartlyUnassignableMethodSignature()
 163    {
 164  1 Object l = new TestPartlyUnassignableMethodSignatureListener();
 165  1 try
 166    {
 167  1 n.addCacheListener(l);
 168  0 fail("Should not accept a cache listener with a bad method signature");
 169    }
 170    catch (IncorrectCacheListenerException icle)
 171    {
 172    // expected
 173    }
 174    }
 175   
 176  1 public void testMultipleMethods()
 177    {
 178  1 Object l = new TestMultipleMethodsListener();
 179  1 n.addCacheListener(l);
 180  1 List invocations = n.listenerInvocations.get(CacheStarted.class);
 181  1 assertEquals(1, invocations.size());
 182  1 invocations = n.listenerInvocations.get(CacheStopped.class);
 183  1 assertEquals(1, invocations.size());
 184  1 assertEquals(1, n.getCacheListeners().size());
 185    }
 186   
 187  1 public void testMultipleAnnotationsOneMethod()
 188    {
 189  1 Object l = new TestMultipleAnnotationsOneMethodListener();
 190  1 n.addCacheListener(l);
 191  1 List invocations = n.listenerInvocations.get(CacheStarted.class);
 192  1 assertEquals(1, invocations.size());
 193  1 invocations = n.listenerInvocations.get(CacheStopped.class);
 194  1 assertEquals(1, invocations.size());
 195  1 assertEquals(1, n.getCacheListeners().size());
 196    }
 197   
 198  1 public void testMultipleMethodsOneAnnotation()
 199    {
 200  1 Object l = new TestMultipleMethodsOneAnnotationListener();
 201  1 n.addCacheListener(l);
 202  1 List invocations = n.listenerInvocations.get(CacheStarted.class);
 203  1 assertEquals(2, invocations.size());
 204  1 assertEquals(1, n.getCacheListeners().size());
 205    }
 206   
 207    @CacheListener
 208    public class TestControlListener
 209    {
 210  0 @CacheStarted
 211    @CacheStopped
 212    public void callback(Event e)
 213    {
 214  0 System.out.println("Hello");
 215    }
 216    }
 217   
 218    @CacheListener
 219    public class TestCacheListenerNoMethodsListener
 220    {
 221  1 public String toString()
 222    {
 223  1 return "Hello";
 224    }
 225    }
 226   
 227    public class TestNonAnnotatedListener
 228    {
 229  0 public String toString()
 230    {
 231  0 return "Hello";
 232    }
 233    }
 234   
 235    @CacheListener
 236    protected class TestNonPublicListener
 237    {
 238  0 @CacheStarted
 239    public void callback()
 240    {
 241    }
 242    }
 243   
 244    @CacheListener
 245    public class TestNonPublicListenerMethodListener
 246    {
 247  0 @CacheStarted
 248    protected void callback(Event e)
 249    {
 250    }
 251    }
 252   
 253    @CacheListener
 254    public class TestNonVoidReturnTypeMethodListener
 255    {
 256  0 @CacheStarted
 257    public String callback(Event e)
 258    {
 259  0 return "Hello";
 260    }
 261    }
 262   
 263    @CacheListener
 264    public class TestIncorrectMethodSignature1Listener
 265    {
 266  0 @CacheStarted
 267    public void callback()
 268    {
 269    }
 270    }
 271   
 272    @CacheListener
 273    public class TestIncorrectMethodSignature2Listener
 274    {
 275  0 @CacheStarted
 276    public void callback(Event e, String s)
 277    {
 278    }
 279    }
 280   
 281    @CacheListener
 282    public class TestIncorrectMethodSignature3Listener
 283    {
 284  0 @CacheStarted
 285    public void callback(Event e, String... s)
 286    {
 287    }
 288    }
 289   
 290    @CacheListener
 291    public class TestUnassignableMethodSignatureListener
 292    {
 293  0 @CacheStarted
 294    public void callback(NodeMovedEvent nme)
 295    {
 296    }
 297    }
 298   
 299    @CacheListener
 300    public class TestPartlyUnassignableMethodSignatureListener
 301    {
 302  0 @NodeMoved
 303    @CacheStarted
 304    public void callback(NodeMovedEvent nme) // sig valid for NodeMoved but not CacheStarted
 305    {
 306    }
 307    }
 308   
 309    @CacheListener
 310    public class TestMultipleMethodsListener
 311    {
 312  0 @CacheStarted
 313    public void callback1(Event e)
 314    {
 315    }
 316   
 317  0 @CacheStopped
 318    public void callback2(Event e)
 319    {
 320    }
 321    }
 322   
 323    @CacheListener
 324    public class TestMultipleAnnotationsOneMethodListener
 325    {
 326  0 @CacheStopped
 327    @CacheStarted
 328    public void callback(Event nme)
 329    {
 330    }
 331    }
 332   
 333    @CacheListener
 334    public class TestMultipleMethodsOneAnnotationListener
 335    {
 336  0 @CacheStarted
 337    public void callback1(Event e)
 338    {
 339    }
 340   
 341  0 @CacheStarted
 342    public void callback2(Event e)
 343    {
 344    }
 345    }
 346    }