1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.enforcer.rules.property;
20
21 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
22 import org.assertj.core.api.Assertions;
23 import org.junit.jupiter.api.Test;
24
25 import static org.junit.jupiter.api.Assertions.fail;
26
27
28
29
30
31
32 class TestRequireEnvironmentVariable {
33
34 private RequireEnvironmentVariable rule = new RequireEnvironmentVariable();
35
36
37
38
39 @Test
40 void testRule() {
41
42 rule.setVariableName("JUNK");
43
44 try {
45 rule.execute();
46 fail("Expected an exception.");
47 } catch (EnforcerRuleException e) {
48
49 }
50
51
52 rule.setVariableName("PATH");
53 try {
54 rule.execute();
55 } catch (EnforcerRuleException e) {
56 fail("This should not throw an exception");
57 }
58 }
59
60
61
62
63
64 @Test
65 void testRuleWithRegex() {
66
67 rule.setVariableName("PATH");
68
69
70 rule.setRegex("[^abc]");
71
72 try {
73 rule.execute();
74 fail("Expected an exception.");
75 } catch (EnforcerRuleException e) {
76
77 }
78
79
80 rule.setRegex(".{1,}");
81 try {
82 rule.execute();
83 } catch (EnforcerRuleException e) {
84 fail("This should not throw an exception");
85 }
86 }
87
88 @Test
89 void ruleShouldBeCached() {
90 rule.setVariableName("TEST");
91 Assertions.assertThat(rule.getCacheId()).isNotEmpty();
92 }
93 }