001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package test;
008:
009: import junit.framework.TestCase;
010: import org.codehaus.aspectwerkz.expression.SubtypePatternType;
011: import org.codehaus.aspectwerkz.expression.regexp.Pattern;
012: import org.codehaus.aspectwerkz.expression.regexp.TypePattern;
013:
014: /**
015: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
016: */
017: public class ClassPatternTest extends TestCase {
018: public void testMatchMethodName1() {
019: TypePattern classPattern = Pattern.compileTypePattern(
020: "foo.bar.SomeClass",
021: SubtypePatternType.NOT_HIERARCHICAL);
022: assertFalse(classPattern.matches("SomeClass"));
023: assertTrue(classPattern.matches("foo.bar.SomeClass"));
024: assertFalse(classPattern.matches("Class"));
025: assertFalse(classPattern.matches(""));
026: }
027:
028: public void testMatchMethodName2() {
029: TypePattern classPattern = Pattern.compileTypePattern(
030: "foo.bar.*", SubtypePatternType.NOT_HIERARCHICAL);
031: assertTrue(classPattern.matches("foo.bar.SomeClass"));
032: assertTrue(classPattern.matches("foo.bar.SomeOtherClass"));
033: assertFalse(classPattern.matches("SomeClass"));
034: assertFalse(classPattern.matches(""));
035: }
036:
037: public void testMatchMethodName3() {
038: TypePattern classPattern = Pattern.compileTypePattern(
039: "foo.*.bar.SomeClass",
040: SubtypePatternType.NOT_HIERARCHICAL);
041: assertTrue(classPattern.matches("foo.hey.bar.SomeClass"));
042: assertTrue(classPattern.matches("foo.there.bar.SomeClass"));
043: assertFalse(classPattern.matches("SomeClass"));
044: assertFalse(classPattern.matches(""));
045: }
046:
047: public void testMatchMethodName4() {
048: TypePattern classPattern = Pattern.compileTypePattern(
049: "foo.ba*.*", SubtypePatternType.NOT_HIERARCHICAL);
050: assertTrue(classPattern.matches("foo.bag.SomeClass"));
051: assertTrue(classPattern.matches("foo.bar.SomeClass"));
052: assertTrue(classPattern.matches("foo.ba.SomeClass"));
053: assertFalse(classPattern.matches("foo.bear.SomeClass"));
054: assertFalse(classPattern.matches("foo"));
055: }
056:
057: public void testMatchClassName5() {
058: TypePattern classPattern = Pattern.compileTypePattern("foo..",
059: SubtypePatternType.NOT_HIERARCHICAL);
060: assertTrue(classPattern.matches("foo.hey.bar.SomeClass"));
061: assertTrue(classPattern.matches("foo.SomeClass"));
062: assertTrue(classPattern.matches("foo.bar.SomeClass"));
063: assertFalse(classPattern.matches("foo"));
064: }
065:
066: public void testMatchClassName6() {
067: TypePattern classPattern = Pattern.compileTypePattern("*",
068: SubtypePatternType.NOT_HIERARCHICAL);
069: assertTrue(classPattern.matches("foo.hey.bar.SomeClass"));
070: assertTrue(classPattern.matches("foo.SomeClass"));
071: assertTrue(classPattern.matches("foo.bar.SomeClass"));
072: assertTrue(classPattern.matches("foo"));
073: }
074:
075: public void testMatchClassName7() {
076: TypePattern classPattern = Pattern.compileTypePattern("..",
077: SubtypePatternType.NOT_HIERARCHICAL);
078: assertTrue(classPattern.matches("foo.hey.bar.SomeClass"));
079: assertTrue(classPattern.matches("foo.SomeClass"));
080: assertTrue(classPattern.matches("foo.bar.SomeClass"));
081: assertTrue(classPattern.matches("foo"));
082: }
083:
084: public void testMatchClassName8() {
085: TypePattern classPattern = Pattern.compileTypePattern(
086: "foo.bar..*", SubtypePatternType.NOT_HIERARCHICAL);
087: assertTrue(classPattern.matches("foo.bar.SomeClass"));
088: assertTrue(classPattern.matches("foo.bar.baz.SomeClass"));
089: assertTrue(classPattern.matches("foo.bar.baz.buzz.SomeClass"));
090: }
091:
092: public void testMatchClassName9() {
093: TypePattern classPattern = Pattern
094: .compileTypePattern("foo.bar.Baz$Buzz",
095: SubtypePatternType.NOT_HIERARCHICAL);
096: assertTrue(classPattern.matches("foo.bar.Baz$Buzz"));
097: assertFalse(classPattern.matches("foo.bar.Baz"));
098: }
099:
100: public void testMatchClassName10() {
101: TypePattern classPattern = Pattern.compileTypePattern(
102: "foo.bar..$Buzz", SubtypePatternType.NOT_HIERARCHICAL);
103: assertTrue(classPattern.matches("foo.bar.Baz$Buzz"));
104: assertTrue(classPattern.matches("foo.bar.Baz.Buz$Buzz"));
105: assertFalse(classPattern.matches("foo.bar.Baz.Buz$Buz"));
106: assertFalse(classPattern.matches("foo.bar.Baz"));
107: }
108:
109: public static void main(String[] args) {
110: junit.textui.TestRunner.run(suite());
111: }
112:
113: public static junit.framework.Test suite() {
114: return new junit.framework.TestSuite(ClassPatternTest.class);
115: }
116: }
|