1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.impl.model.profile;
20
21 import java.nio.file.Path;
22 import java.util.Map;
23
24 import org.apache.maven.api.model.Model;
25 import org.apache.maven.api.model.Profile;
26 import org.apache.maven.api.services.model.ProfileActivationContext;
27 import org.apache.maven.api.services.model.ProfileActivator;
28 import org.apache.maven.impl.model.DefaultInterpolator;
29 import org.apache.maven.impl.model.DefaultPathTranslator;
30 import org.apache.maven.impl.model.DefaultProfileActivationContext;
31 import org.apache.maven.impl.model.rootlocator.DefaultRootLocator;
32 import org.junit.jupiter.api.AfterEach;
33 import org.junit.jupiter.api.BeforeEach;
34
35 import static org.junit.jupiter.api.Assertions.assertEquals;
36
37
38
39
40
41
42 public abstract class AbstractProfileActivatorTest<T extends ProfileActivator> {
43 static class FakeRootLocator extends DefaultRootLocator {
44 @Override
45 protected boolean isRootDirectory(Path dir) {
46 return true;
47 }
48 }
49
50 protected T activator;
51
52 @BeforeEach
53 abstract void setUp() throws Exception;
54
55 @AfterEach
56 void tearDown() throws Exception {
57 activator = null;
58 }
59
60 protected DefaultProfileActivationContext newContext() {
61 return new DefaultProfileActivationContext(
62 new DefaultPathTranslator(), new FakeRootLocator(), new DefaultInterpolator());
63 }
64
65 protected ProfileActivationContext newContext(
66 Map<String, String> userProperties, Map<String, String> systemProperties) {
67 return newContext()
68 .setUserProperties(userProperties)
69 .setSystemProperties(systemProperties)
70 .setModel(Model.newInstance());
71 }
72
73 protected void assertActivation(boolean active, Profile profile, ProfileActivationContext context) {
74 SimpleProblemCollector problems = new SimpleProblemCollector();
75
76 boolean res = activator.isActive(profile, context, problems);
77 assertEquals(0, problems.getErrors().size(), problems.getErrors().toString());
78 assertEquals(0, problems.getWarnings().size(), problems.getWarnings().toString());
79 assertEquals(active, res);
80 }
81 }