1 package org.codehaus.plexus.interpolation;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 }