1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.model.profile.activation;
20
21 import java.util.Properties;
22
23 import org.apache.maven.api.model.Activation;
24 import org.apache.maven.api.model.Profile;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27
28
29
30
31
32 class JdkVersionProfileActivatorTest extends AbstractProfileActivatorTest<JdkVersionProfileActivator> {
33
34 @Override
35 @BeforeEach
36 void setUp() throws Exception {
37 activator = new JdkVersionProfileActivator();
38 }
39
40 private Profile newProfile(String jdkVersion) {
41 Activation a = Activation.newBuilder().jdk(jdkVersion).build();
42
43 Profile p = Profile.newBuilder().activation(a).build();
44
45 return p;
46 }
47
48 private Properties newProperties(String javaVersion) {
49 Properties props = new Properties();
50 props.setProperty("java.version", javaVersion);
51 return props;
52 }
53
54 @Test
55 void testNullSafe() throws Exception {
56 Profile p = Profile.newInstance();
57
58 assertActivation(false, p, newContext(null, null));
59
60 p = p.withActivation(Activation.newInstance());
61
62 assertActivation(false, p, newContext(null, null));
63 }
64
65 @Test
66 void testPrefix() throws Exception {
67 Profile profile = newProfile("1.4");
68
69 assertActivation(true, profile, newContext(null, newProperties("1.4")));
70 assertActivation(true, profile, newContext(null, newProperties("1.4.2")));
71 assertActivation(true, profile, newContext(null, newProperties("1.4.2_09")));
72 assertActivation(true, profile, newContext(null, newProperties("1.4.2_09-b03")));
73
74 assertActivation(false, profile, newContext(null, newProperties("1.3")));
75
76 assertActivation(false, profile, newContext(null, newProperties("1.5")));
77 }
78
79 @Test
80 void testPrefixNegated() throws Exception {
81 Profile profile = newProfile("!1.4");
82
83 assertActivation(false, profile, newContext(null, newProperties("1.4")));
84 assertActivation(false, profile, newContext(null, newProperties("1.4.2")));
85 assertActivation(false, profile, newContext(null, newProperties("1.4.2_09")));
86 assertActivation(false, profile, newContext(null, newProperties("1.4.2_09-b03")));
87
88 assertActivation(true, profile, newContext(null, newProperties("1.3")));
89
90 assertActivation(true, profile, newContext(null, newProperties("1.5")));
91 }
92
93 @Test
94 void testVersionRangeInclusiveBounds() throws Exception {
95 Profile profile = newProfile("[1.5,1.6]");
96
97 assertActivation(false, profile, newContext(null, newProperties("1.4")));
98 assertActivation(false, profile, newContext(null, newProperties("1.4.2")));
99 assertActivation(false, profile, newContext(null, newProperties("1.4.2_09")));
100 assertActivation(false, profile, newContext(null, newProperties("1.4.2_09-b03")));
101
102 assertActivation(true, profile, newContext(null, newProperties("1.5")));
103 assertActivation(true, profile, newContext(null, newProperties("1.5.0")));
104 assertActivation(true, profile, newContext(null, newProperties("1.5.0_09")));
105 assertActivation(true, profile, newContext(null, newProperties("1.5.0_09-b03")));
106 assertActivation(true, profile, newContext(null, newProperties("1.5.1")));
107
108 assertActivation(true, profile, newContext(null, newProperties("1.6")));
109 assertActivation(true, profile, newContext(null, newProperties("1.6.0")));
110 assertActivation(true, profile, newContext(null, newProperties("1.6.0_09")));
111 assertActivation(true, profile, newContext(null, newProperties("1.6.0_09-b03")));
112 }
113
114 @Test
115 void testVersionRangeExclusiveBounds() throws Exception {
116 Profile profile = newProfile("(1.3,1.6)");
117
118 assertActivation(false, profile, newContext(null, newProperties("1.3")));
119 assertActivation(false, profile, newContext(null, newProperties("1.3.0")));
120 assertActivation(false, profile, newContext(null, newProperties("1.3.0_09")));
121 assertActivation(false, profile, newContext(null, newProperties("1.3.0_09-b03")));
122
123 assertActivation(true, profile, newContext(null, newProperties("1.3.1")));
124 assertActivation(true, profile, newContext(null, newProperties("1.3.1_09")));
125 assertActivation(true, profile, newContext(null, newProperties("1.3.1_09-b03")));
126
127 assertActivation(true, profile, newContext(null, newProperties("1.5")));
128 assertActivation(true, profile, newContext(null, newProperties("1.5.0")));
129 assertActivation(true, profile, newContext(null, newProperties("1.5.0_09")));
130 assertActivation(true, profile, newContext(null, newProperties("1.5.0_09-b03")));
131 assertActivation(true, profile, newContext(null, newProperties("1.5.1")));
132
133 assertActivation(false, profile, newContext(null, newProperties("1.6")));
134 }
135
136 @Test
137 void testVersionRangeInclusiveLowerBound() throws Exception {
138 Profile profile = newProfile("[1.5,)");
139
140 assertActivation(false, profile, newContext(null, newProperties("1.4")));
141 assertActivation(false, profile, newContext(null, newProperties("1.4.2")));
142 assertActivation(false, profile, newContext(null, newProperties("1.4.2_09")));
143 assertActivation(false, profile, newContext(null, newProperties("1.4.2_09-b03")));
144
145 assertActivation(true, profile, newContext(null, newProperties("1.5")));
146 assertActivation(true, profile, newContext(null, newProperties("1.5.0")));
147 assertActivation(true, profile, newContext(null, newProperties("1.5.0_09")));
148 assertActivation(true, profile, newContext(null, newProperties("1.5.0_09-b03")));
149 assertActivation(true, profile, newContext(null, newProperties("1.5.1")));
150
151 assertActivation(true, profile, newContext(null, newProperties("1.6")));
152 assertActivation(true, profile, newContext(null, newProperties("1.6.0")));
153 assertActivation(true, profile, newContext(null, newProperties("1.6.0_09")));
154 assertActivation(true, profile, newContext(null, newProperties("1.6.0_09-b03")));
155 }
156
157 @Test
158 void testVersionRangeExclusiveUpperBound() throws Exception {
159 Profile profile = newProfile("(,1.6)");
160
161 assertActivation(true, profile, newContext(null, newProperties("1.5")));
162 assertActivation(true, profile, newContext(null, newProperties("1.5.0")));
163 assertActivation(true, profile, newContext(null, newProperties("1.5.0_09")));
164 assertActivation(true, profile, newContext(null, newProperties("1.5.0_09-b03")));
165 assertActivation(true, profile, newContext(null, newProperties("1.5.1")));
166
167 assertActivation(false, profile, newContext(null, newProperties("1.6")));
168 assertActivation(false, profile, newContext(null, newProperties("1.6.0")));
169 assertActivation(false, profile, newContext(null, newProperties("1.6.0_09")));
170 assertActivation(false, profile, newContext(null, newProperties("1.6.0_09-b03")));
171 }
172 }