1 25 26 package org.snipsnap.test.interceptor; 27 28 import junit.framework.Test; 29 import junit.framework.TestCase; 30 import junit.framework.TestSuite; 31 import org.snipsnap.interceptor.Aspects; 32 import org.snipsnap.interceptor.custom.MissingInterceptor; 33 import org.snipsnap.snip.SnipSpace; 34 import org.snipsnap.test.mock.MockObject; 35 import org.snipsnap.test.mock.MockSnipSpace; 36 37 import java.lang.reflect.Proxy ; 38 39 public class MissingInterceptorTest extends TestCase { 40 private MockObject mock; 41 private SnipSpace space; 42 private MissingInterceptor interceptor; 43 44 public MissingInterceptorTest(String name) { 45 super(name); 46 } 47 48 protected void setUp() throws Exception { 49 super.setUp(); 50 mock = new MockSnipSpace(); 51 Aspects aspect = new Aspects(mock); 52 space = (SnipSpace) Proxy.newProxyInstance(MockSnipSpace.class.getClassLoader(), 53 new Class []{SnipSpace.class}, aspect); 54 55 interceptor = new MissingInterceptor(); 56 aspect.addInterceptor(interceptor); 57 } 58 59 public static Test suite() { 60 return new TestSuite(MissingInterceptorTest.class); 61 } 62 63 public void testExistsUsesCache() { 64 space.exists("TestSnip"); assertEquals("Exists() called once", 1, mock.getCount("exists")); 66 space.exists("TestSnip"); assertEquals("Exists() not called when in cache", 1, mock.getCount("exists")); 68 } 69 70 public void testMissingExists() { 71 assertTrue("Snip does not exist", !space.exists("TestSnip")); 72 assertTrue("Snip is in missing set", interceptor.getMissing().contains("TESTSNIP")); 73 } 74 75 public void testMissingCreate() { 76 space.exists("TestSnip"); 77 space.create("TestSnip", "TestContent"); 78 assertTrue("Snip is not missing set", !interceptor.getMissing().contains("TestSnip")); 79 assertEquals("MissingInterceptor calls create()", 1, mock.getCount("create")); 80 } 81 82 } 83 | Popular Tags |