View Javadoc
1   /*
2    * The MIT License (MIT)
3    *
4    * Copyright (c) 2013-2026 The Coveralls Maven Plugin Project Contributors:
5    *     https://github.com/hazendaz/coveralls-maven-plugin/graphs/contributors
6    *
7    * Permission is hereby granted, free of charge, to any person obtaining a copy
8    * of this software and associated documentation files (the "Software"), to deal
9    * in the Software without restriction, including without limitation the rights
10   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11   * copies of the Software, and to permit persons to whom the Software is
12   * furnished to do so, subject to the following conditions:
13   *
14   * The above copyright notice and this permission notice shall be included in
15   * all copies or substantial portions of the Software.
16   *
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23   * THE SOFTWARE.
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   * The Class AbstractServiceSetupTest.
36   */
37  class AbstractServiceSetupTest {
38  
39      /**
40       * Gets the missing property.
41       */
42      @Test
43      void missingProperty() {
44          final var serviceSetup = this.create(new HashMap<>());
45          Assertions.assertNull(serviceSetup.getProperty("property"));
46      }
47  
48      /**
49       * Test get property.
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       * Adds the property without name.
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       * Adds the property without value.
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       * Adds the property with value.
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       * Gets the default values.
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      * Creates the.
105      *
106      * @param env
107      *            the env
108      *
109      * @return the abstract service setup
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 }