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  
30  import org.junit.jupiter.api.Assertions;
31  import org.junit.jupiter.api.Test;
32  
33  /**
34   * The Class ShippableTest.
35   */
36  class ShippableTest {
37  
38      /**
39       * Env.
40       *
41       * @return the map
42       */
43      Map<String, String> env() {
44          final Map<String, String> env = new HashMap<>();
45          env.put(Shippable.SHIPPABLE, "true");
46          env.put(Shippable.SHIPPABLE_BUILD_ID, "54de3316c44f");
47          env.put(Shippable.SHIPPABLE_BUILD_NUMBER, "431.1");
48          env.put(Shippable.SHIPPABLE_BRANCH, "master");
49          env.put(Shippable.SHIPPABLE_COMMIT, "a3562fgcd2");
50          env.put(Shippable.SHIPPABLE_PULL_REQUEST, "10");
51          return env;
52      }
53  
54      /**
55       * Checks if is selected for nothing.
56       */
57      @Test
58      void isSelectedForNothing() {
59          Assertions.assertFalse(new Shippable(new HashMap<>()).isSelected());
60      }
61  
62      /**
63       * Checks if is selected for shippable.
64       */
65      @Test
66      void isSelectedForShippable() {
67          Assertions.assertTrue(new Shippable(this.env()).isSelected());
68      }
69  
70      /**
71       * Test get name.
72       */
73      @Test
74      void name() {
75          Assertions.assertEquals("shippable", new Shippable(this.env()).getName());
76      }
77  
78      /**
79       * Test get build number.
80       */
81      @Test
82      void buildNumber() {
83          Assertions.assertEquals("431.1", new Shippable(this.env()).getBuildNumber());
84      }
85  
86      /**
87       * Test get build url.
88       */
89      @Test
90      void buildUrl() {
91          Assertions.assertEquals("https://app.shippable.com/builds/54de3316c44f",
92                  new Shippable(this.env()).getBuildUrl());
93      }
94  
95      /**
96       * Test get branch.
97       */
98      @Test
99      void branch() {
100         Assertions.assertEquals("master", new Shippable(this.env()).getBranch());
101     }
102 
103     /**
104      * Pull request.
105      */
106     @Test
107     void pullRequest() {
108         Assertions.assertEquals("10", new Shippable(this.env()).getPullRequest());
109     }
110 
111     /**
112      * Pull request false.
113      */
114     @Test
115     void pullRequestFalse() {
116         final var env = this.env();
117         env.put(Shippable.SHIPPABLE_PULL_REQUEST, "false");
118         Assertions.assertNull(new Shippable(env).getPullRequest());
119     }
120 
121     /**
122      * Test get environment.
123      */
124     @Test
125     void environment() {
126         final var properties = new Shippable(this.env()).getEnvironment();
127         Assertions.assertEquals(5, properties.size());
128         Assertions.assertEquals("431.1", properties.getProperty("shippable_build_number"));
129         Assertions.assertEquals("54de3316c44f", properties.getProperty("shippable_build_id"));
130         Assertions.assertEquals("https://app.shippable.com/builds/54de3316c44f",
131                 properties.getProperty("shippable_build_url"));
132         Assertions.assertEquals("master", properties.getProperty("branch"));
133         Assertions.assertEquals("a3562fgcd2", properties.getProperty("commit_sha"));
134     }
135 
136 }