1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.eluder.coveralls.maven.plugin.service;
26
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.Properties;
30
31 import org.junit.jupiter.api.Assertions;
32 import org.junit.jupiter.api.Test;
33
34
35
36
37 class AbstractServiceSetupTest {
38
39
40
41
42 @Test
43 void missingProperty() {
44 final var serviceSetup = this.create(new HashMap<>());
45 Assertions.assertNull(serviceSetup.getProperty("property"));
46 }
47
48
49
50
51 @Test
52 void property() {
53 final Map<String, String> env = new HashMap<>();
54 env.put("CI_NAME", "bamboo");
55 Assertions.assertEquals("bamboo", this.create(env).getProperty("CI_NAME"));
56 }
57
58
59
60
61 @Test
62 void addPropertyWithoutName() {
63 final var setup = this.create(new HashMap<>());
64 final var properties = new Properties();
65 Assertions.assertThrows(IllegalArgumentException.class, () -> setup.addProperty(properties, null, "value"));
66 }
67
68
69
70
71 @Test
72 void addPropertyWithoutValue() {
73 final var properties = new Properties();
74 this.create(new HashMap<>()).addProperty(properties, "prop", " ");
75 Assertions.assertNull(properties.getProperty("prop"));
76 }
77
78
79
80
81 @Test
82 void addPropertyWithValue() {
83 final var properties = new Properties();
84 this.create(new HashMap<>()).addProperty(properties, "prop", "value");
85 Assertions.assertEquals("value", properties.getProperty("prop"));
86 }
87
88
89
90
91 @Test
92 void defaultValues() {
93 final var serviceSetup = this.create(new HashMap<>());
94 Assertions.assertNull(serviceSetup.getName());
95 Assertions.assertNull(serviceSetup.getJobId());
96 Assertions.assertNull(serviceSetup.getBuildNumber());
97 Assertions.assertNull(serviceSetup.getBuildUrl());
98 Assertions.assertNull(serviceSetup.getBranch());
99 Assertions.assertNull(serviceSetup.getPullRequest());
100 Assertions.assertNull(serviceSetup.getEnvironment());
101 }
102
103
104
105
106
107
108
109
110
111 private AbstractServiceSetup create(final Map<String, String> env) {
112 return new AbstractServiceSetup(env) {
113 @Override
114 public boolean isSelected() {
115 return true;
116 }
117
118 @Override
119 public String getName() {
120 return this.getProperty("CI_NAME");
121 }
122 };
123 }
124
125 }