KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > aop > defaults > NameMatchesComponentPointcutTestCase


1 /*****************************************************************************
2  * Copyright (c) PicoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Idea by Rachel Davies, Original code by various *
9  *****************************************************************************/

10 package org.nanocontainer.aop.defaults;
11
12 import junit.framework.TestCase;
13 import org.nanocontainer.aop.ComponentPointcut;
14 import org.nanocontainer.aop.MalformedRegularExpressionException;
15 import org.nanocontainer.testmodel.Dao;
16
17 /**
18  * @author Stephen Molitor
19  */

20 public class NameMatchesComponentPointcutTestCase extends TestCase {
21
22     public void testPicks() throws Exception JavaDoc {
23         ComponentPointcut cut1 = new NameMatchesComponentPointcut("^foo$");
24         assertTrue(cut1.picks("foo"));
25         assertFalse(cut1.picks("barfoo"));
26         assertFalse(cut1.picks("foobar"));
27
28         ComponentPointcut cut2 = new NameMatchesComponentPointcut("foo*");
29         assertTrue(cut2.picks("foo"));
30         assertTrue(cut2.picks("barfoo"));
31         assertTrue(cut2.picks("foobar"));
32     }
33
34     public void testNotStringComponentKey() {
35         ComponentPointcut cut = new NameMatchesComponentPointcut("foo");
36         assertFalse(cut.picks(Dao.class));
37     }
38
39     public void testConstructorThrowsMalformedRegularExpressionException() {
40         try {
41             new NameMatchesComponentPointcut("(");
42             fail("MalformedRegularExpression exception should have been raised");
43         } catch (MalformedRegularExpressionException e) {
44         }
45     }
46
47 }
Popular Tags