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;
20
21 import java.util.Collections;
22 import java.util.List;
23
24 import org.apache.maven.model.Activation;
25 import org.apache.maven.model.Profile;
26 import org.apache.maven.model.building.ModelProblemCollector;
27 import org.apache.maven.model.building.SimpleProblemCollector;
28 import org.apache.maven.model.profile.activation.ProfileActivator;
29 import org.junit.jupiter.api.Test;
30
31 import static org.junit.jupiter.api.Assertions.assertEquals;
32 import static org.junit.jupiter.api.Assertions.assertTrue;
33
34
35
36
37 public class DefaultProfileSelectorTest {
38 private Profile newProfile(String id) {
39 Activation activation = new Activation();
40 Profile profile = new Profile();
41 profile.setId(id);
42 profile.setActivation(activation);
43 return profile;
44 }
45
46 @Test
47 void testThrowingActivator() {
48 DefaultProfileSelector selector = new DefaultProfileSelector();
49 selector.addProfileActivator(new ProfileActivator() {
50 @Override
51 public boolean isActive(Profile profile, ProfileActivationContext context, ModelProblemCollector problems) {
52 throw new RuntimeException("BOOM");
53 }
54
55 @Override
56 public boolean presentInConfig(
57 Profile profile, ProfileActivationContext context, ModelProblemCollector problems) {
58 return true;
59 }
60 });
61
62 List<Profile> profiles = Collections.singletonList(newProfile("one"));
63 DefaultProfileActivationContext context = new DefaultProfileActivationContext();
64 SimpleProblemCollector problems = new SimpleProblemCollector();
65 List<Profile> active = selector.getActiveProfiles(profiles, context, problems);
66 assertTrue(active.isEmpty());
67 assertEquals(1, problems.getErrors().size());
68 assertEquals(
69 "Failed to determine activation for profile one: BOOM",
70 problems.getErrors().get(0));
71 }
72 }