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.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
36
37 class JobValidatorTest {
38
39
40
41
42 @Test
43 void missingJob() {
44 org.junit.jupiter.api.Assertions.assertThrows(IllegalArgumentException.class, () -> new JobValidator(null));
45 }
46
47
48
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
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
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
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
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
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
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
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 }