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 GitHubTest.
35   */
36  class GitHubTest {
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("GITHUB_ACTIONS", "true");
46          env.put("GITHUB_REPOSITORY", "hazendaz/coveralls-maven-plugin");
47          env.put("GITHUB_REF", "refs/pull/1/merge");
48          env.put("GITHUB_REF_NAME", "main");
49          env.put("GITHUB_RUN_ID", "12345");
50          env.put("GITHUB_RUN_NUMBER", "1");
51          env.put("GITHUB_SERVER_URL", "https://github.com");
52          return env;
53      }
54  
55      /**
56       * Checks if is selected for nothing.
57       */
58      @Test
59      void isSelectedForNothing() {
60          Assertions.assertFalse(new GitHub(new HashMap<>()).isSelected());
61      }
62  
63      /**
64       * Checks if is selected for jenkins.
65       */
66      @Test
67      void isSelectedForJenkins() {
68          Assertions.assertTrue(new GitHub(this.env()).isSelected());
69      }
70  
71      /**
72       * Test get name.
73       */
74      @Test
75      void name() {
76          Assertions.assertEquals("github", new GitHub(this.env()).getName());
77      }
78  
79      /**
80       * Test get build number.
81       */
82      @Test
83      void buildNumber() {
84          Assertions.assertEquals("1", new GitHub(this.env()).getBuildNumber());
85      }
86  
87      /**
88       * Test get build url.
89       */
90      @Test
91      void buildUrl() {
92          Assertions.assertEquals("https://github.com/hazendaz/coveralls-maven-plugin/actions/runs/12345",
93                  new GitHub(this.env()).getBuildUrl());
94      }
95  
96      /**
97       * Test get pull request.
98       */
99      @Test
100     void pullRequest() {
101         Assertions.assertEquals("1", new GitHub(this.env()).getPullRequest());
102     }
103 
104     /**
105      * Test get job id.
106      */
107     @Test
108     void jobId() {
109         Assertions.assertEquals("12345", new GitHub(this.env()).getJobId());
110     }
111 
112 }