KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > test > interceptor > MissingInterceptorTest


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

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 JavaDoc;
38
39 public class MissingInterceptorTest extends TestCase {
40   private MockObject mock;
41   private SnipSpace space;
42   private MissingInterceptor interceptor;
43
44   public MissingInterceptorTest(String JavaDoc name) {
45     super(name);
46   }
47
48   protected void setUp() throws Exception JavaDoc {
49     super.setUp();
50     mock = new MockSnipSpace();
51     Aspects aspect = new Aspects(mock);
52     space = (SnipSpace) Proxy.newProxyInstance(MockSnipSpace.class.getClassLoader(),
53         new Class JavaDoc[]{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"); // put in missing cache
65
assertEquals("Exists() called once", 1, mock.getCount("exists"));
66     space.exists("TestSnip"); // should read from cache
67
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