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 org.junit.jupiter.api.Test;
23  
24  import static org.junit.jupiter.api.Assertions.assertEquals;
25  import static org.junit.jupiter.api.Assertions.assertFalse;
26  import static org.junit.jupiter.api.Assertions.assertTrue;
27  
28  public class PrefixAwareRecursionInterceptorTest {
29  
30      @Test
31      public void testFindExpression() {
32          PrefixAwareRecursionInterceptor receptor =
33                  new PrefixAwareRecursionInterceptor(Collections.singleton("prefix."));
34  
35          String expr = "prefix.first";
36  
37          receptor.expressionResolutionStarted(expr);
38  
39          assertTrue(receptor.hasRecursiveExpression(expr));
40          assertEquals("[first]", receptor.getExpressionCycle(expr).toString());
41  
42          receptor.expressionResolutionFinished(expr);
43  
44          assertFalse(receptor.hasRecursiveExpression(expr));
45      }
46  
47      @Test
48      public void testFindExpressionWithDifferentPrefix() {
49          PrefixAwareRecursionInterceptor receptor =
50                  new PrefixAwareRecursionInterceptor(Arrays.asList(new String[] {"prefix.", "other."}));
51  
52          String expr = "prefix.first";
53  
54          receptor.expressionResolutionStarted(expr);
55  
56          assertTrue(receptor.hasRecursiveExpression(expr));
57  
58          receptor.expressionResolutionFinished(expr);
59  
60          assertFalse(receptor.hasRecursiveExpression(expr));
61      }
62  
63      @Test
64      public void testFindExpressionWithoutPrefix() {
65          PrefixAwareRecursionInterceptor receptor =
66                  new PrefixAwareRecursionInterceptor(Arrays.asList(new String[] {"prefix.", "other."}));
67  
68          String prefixedExpr = "prefix.first";
69          String expr = "first";
70  
71          receptor.expressionResolutionStarted(prefixedExpr);
72  
73          assertTrue(receptor.hasRecursiveExpression(expr));
74  
75          receptor.expressionResolutionFinished(prefixedExpr);
76  
77          assertFalse(receptor.hasRecursiveExpression(expr));
78      }
79  }