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.validation;
26  
27  import org.assertj.core.api.Assertions;
28  import org.eluder.coveralls.maven.plugin.domain.Git;
29  import org.eluder.coveralls.maven.plugin.domain.Git.Head;
30  import org.eluder.coveralls.maven.plugin.domain.Job;
31  import org.eluder.coveralls.maven.plugin.validation.ValidationError.Level;
32  import org.junit.jupiter.api.Test;
33  
34  /**
35   * The Class JobValidatorTest.
36   */
37  class JobValidatorTest {
38  
39      /**
40       * Missing job.
41       */
42      @Test
43      void missingJob() {
44          org.junit.jupiter.api.Assertions.assertThrows(IllegalArgumentException.class, () -> new JobValidator(null));
45      }
46  
47      /**
48       * Validate without repo token or travis.
49       */
50      @Test
51      void validateWithoutRepoTokenOrTravis() {
52          final var errors = new JobValidator(new Job()).validate();
53          Assertions.assertThat(errors).hasSize(1);
54          Assertions.assertThat(errors.get(0).getLevel()).isEqualByComparingTo(Level.ERROR);
55      }
56  
57      /**
58       * Validate without repo token or travis for dry run.
59       */
60      @Test
61      void validateWithoutRepoTokenOrTravisForDryRun() {
62          final var errors = new JobValidator(new Job().withDryRun(true)).validate();
63          Assertions.assertThat(errors).hasSize(1);
64          Assertions.assertThat(errors.get(0).getLevel()).isEqualByComparingTo(Level.WARN);
65      }
66  
67      /**
68       * Validate with invalid travis.
69       */
70      @Test
71      void validateWithInvalidTravis() {
72          final var errors = new JobValidator(new Job().withServiceName("travis-ci")).validate();
73          Assertions.assertThat(errors).hasSize(1);
74          Assertions.assertThat(errors.get(0).getLevel()).isEqualByComparingTo(Level.ERROR);
75      }
76  
77      /**
78       * Validate with repo token.
79       */
80      @Test
81      void validateWithRepoToken() {
82          final var errors = new JobValidator(new Job().withRepoToken("ad3fg5")).validate();
83          Assertions.assertThat(errors).isEmpty();
84      }
85  
86      /**
87       * Validate with travis.
88       */
89      @Test
90      void validateWithTravis() {
91          final var errors = new JobValidator(new Job().withServiceName("travis-ci").withServiceJobId("123")).validate();
92          Assertions.assertThat(errors).isEmpty();
93      }
94  
95      /**
96       * Validate without git commit id.
97       */
98      @Test
99      void validateWithoutGitCommitId() {
100         final var git = new Git(null, new Head(null, null, null, null, null, null), null, null);
101         final var errors = new JobValidator(new Job().withRepoToken("ad3fg5").withGit(git)).validate();
102         Assertions.assertThat(errors).hasSize(1);
103         Assertions.assertThat(errors.get(0).getLevel()).isEqualByComparingTo(Level.ERROR);
104     }
105 
106     /**
107      * Validate with git.
108      */
109     @Test
110     void validateWithGit() {
111         final var git = new Git(null, new Head("bc23af5", null, null, null, null, null), null, null);
112         final var errors = new JobValidator(new Job().withRepoToken("ad3fg5").withGit(git)).validate();
113         Assertions.assertThat(errors).isEmpty();
114     }
115 
116     /**
117      * Validate with parallel.
118      */
119     @Test
120     void validateWithParallel() {
121         final var errors = new JobValidator(new Job().withRepoToken("ad3fg5").withParallel(true)).validate();
122         Assertions.assertThat(errors).isEmpty();
123     }
124 
125 }