View Javadoc
1   package org.codehaus.plexus.interpolation;
2   
3   /*
4    * Copyright 2001-2008 Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.util.Arrays;
20  import java.util.Collections;
21  
22  import junit.framework.TestCase;
23  
24  public class PrefixAwareRecursionInterceptorTest
25      extends TestCase
26  {
27  
28      public void testFindExpression()
29      {
30          PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor(
31                                                                                          Collections.singleton( "prefix." ) );
32  
33          String expr = "prefix.first";
34  
35          receptor.expressionResolutionStarted( expr );
36  
37          assertTrue( receptor.hasRecursiveExpression( expr ) );
38          assertEquals( "[first]", receptor.getExpressionCycle( expr ).toString() );
39  
40          receptor.expressionResolutionFinished( expr );
41  
42          assertFalse( receptor.hasRecursiveExpression( expr ) );
43      }
44  
45      public void testFindExpressionWithDifferentPrefix()
46      {
47          PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor(
48                                                                                          Arrays.asList( new String[] {
49                                                                                              "prefix.",
50                                                                                              "other."
51                                                                                          } ) );
52  
53          String expr = "prefix.first";
54  
55          receptor.expressionResolutionStarted( expr );
56  
57          assertTrue( receptor.hasRecursiveExpression( expr ) );
58  
59          receptor.expressionResolutionFinished( expr );
60  
61          assertFalse( receptor.hasRecursiveExpression( expr ) );
62      }
63  
64      public void testFindExpressionWithoutPrefix()
65      {
66          PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor(
67                                                                                          Arrays.asList( new String[] {
68                                                                                              "prefix.",
69                                                                                              "other."
70                                                                                          } ) );
71  
72          String prefixedExpr = "prefix.first";
73          String expr = "first";
74  
75          receptor.expressionResolutionStarted( prefixedExpr );
76  
77          assertTrue( receptor.hasRecursiveExpression( expr ) );
78  
79          receptor.expressionResolutionFinished( prefixedExpr );
80  
81          assertFalse( receptor.hasRecursiveExpression( expr ) );
82      }
83  
84  }