01: /*****************************************************************************
02: * Copyright (c) PicoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: * Idea by Rachel Davies, Original code by various *
09: *****************************************************************************/package org.nanocontainer.aop.defaults;
10:
11: import junit.framework.TestCase;
12: import org.nanocontainer.aop.ComponentPointcut;
13: import org.nanocontainer.aop.MalformedRegularExpressionException;
14: import org.nanocontainer.testmodel.Dao;
15:
16: /**
17: * @author Stephen Molitor
18: */
19: public class NameMatchesComponentPointcutTestCase extends TestCase {
20:
21: public void testPicks() throws Exception {
22: ComponentPointcut cut1 = new NameMatchesComponentPointcut(
23: "^foo$");
24: assertTrue(cut1.picks("foo"));
25: assertFalse(cut1.picks("barfoo"));
26: assertFalse(cut1.picks("foobar"));
27:
28: ComponentPointcut cut2 = new NameMatchesComponentPointcut(
29: "foo*");
30: assertTrue(cut2.picks("foo"));
31: assertTrue(cut2.picks("barfoo"));
32: assertTrue(cut2.picks("foobar"));
33: }
34:
35: public void testNotStringComponentKey() {
36: ComponentPointcut cut = new NameMatchesComponentPointcut("foo");
37: assertFalse(cut.picks(Dao.class));
38: }
39:
40: public void testConstructorThrowsMalformedRegularExpressionException() {
41: try {
42: new NameMatchesComponentPointcut("(");
43: fail("MalformedRegularExpression exception should have been raised");
44: } catch (MalformedRegularExpressionException e) {
45: }
46: }
47:
48: }
|