001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.classreader;
034:
035: import junit.framework.*;
036:
037: public class TestStrictDispatcher extends TestCase {
038: private ClassfileLoaderDispatcher dispatcher;
039:
040: protected void setUp() throws Exception {
041: super .setUp();
042:
043: dispatcher = new StrictDispatcher();
044: }
045:
046: public void testDispatch() {
047: assertEquals("foo.class",
048: ClassfileLoaderDispatcher.Action.CLASS, dispatcher
049: .dispatch("foo.class"));
050:
051: assertEquals("src", ClassfileLoaderDispatcher.Action.DIRECTORY,
052: dispatcher.dispatch("src"));
053:
054: assertEquals("MANIFEST.MF",
055: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
056: .dispatch("MANIFEST.MF"));
057: assertEquals("foo.bat",
058: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
059: .dispatch("foo.bat"));
060: assertEquals("foo.css",
061: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
062: .dispatch("foo.css"));
063: assertEquals("foo.dtd",
064: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
065: .dispatch("foo.dtd"));
066: assertEquals("foo.gif",
067: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
068: .dispatch("foo.gif"));
069: assertEquals("foo.htm",
070: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
071: .dispatch("foo.htm"));
072: assertEquals("foo.html",
073: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
074: .dispatch("foo.html"));
075: assertEquals("foo.java",
076: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
077: .dispatch("foo.java"));
078: assertEquals("foo.jpeg",
079: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
080: .dispatch("foo.jpeg"));
081: assertEquals("foo.jpg",
082: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
083: .dispatch("foo.jpg"));
084: assertEquals("foo.js", ClassfileLoaderDispatcher.Action.IGNORE,
085: dispatcher.dispatch("foo.js"));
086: assertEquals("foo.jsp",
087: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
088: .dispatch("foo.jsp"));
089: assertEquals("foo.properties",
090: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
091: .dispatch("foo.properties"));
092: assertEquals("foo.ps", ClassfileLoaderDispatcher.Action.IGNORE,
093: dispatcher.dispatch("foo.ps"));
094: assertEquals("foo.txt",
095: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
096: .dispatch("foo.txt"));
097: assertEquals("foo.xml",
098: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
099: .dispatch("foo.xml"));
100: assertEquals("foo.xsl",
101: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
102: .dispatch("foo.xsl"));
103: assertEquals("foo/", ClassfileLoaderDispatcher.Action.IGNORE,
104: dispatcher.dispatch("foo/"));
105:
106: assertEquals("foo.jar", ClassfileLoaderDispatcher.Action.JAR,
107: dispatcher.dispatch("foo.jar"));
108:
109: assertEquals("foo.zip", ClassfileLoaderDispatcher.Action.ZIP,
110: dispatcher.dispatch("foo.zip"));
111:
112: assertEquals("foo.foo",
113: ClassfileLoaderDispatcher.Action.IGNORE, dispatcher
114: .dispatch("foo.foo"));
115: }
116: }
|