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 com.googlecode.catchexception.CatchException;
28
29 import java.util.Collections;
30
31 import org.apache.maven.plugin.logging.Log;
32 import org.eluder.coveralls.maven.plugin.validation.ValidationError.Level;
33 import org.junit.jupiter.api.Assertions;
34 import org.junit.jupiter.api.Test;
35 import org.junit.jupiter.api.extension.ExtendWith;
36 import org.mockito.ArgumentMatchers;
37 import org.mockito.Mock;
38 import org.mockito.Mockito;
39 import org.mockito.junit.jupiter.MockitoExtension;
40
41 /**
42 * The Class ValidationErrorsTest.
43 */
44 @ExtendWith(MockitoExtension.class)
45 class ValidationErrorsTest {
46
47 /** The log mock. */
48 @Mock
49 private Log logMock;
50
51 /**
52 * Throw or inform with error.
53 */
54 @Test
55 void throwOrInformWithError() {
56 final var errors = this.createValidationErrors(new ValidationError(Level.ERROR, "message"));
57 CatchException.catchException(() -> errors.throwOrInform(this.logMock));
58 Assertions.assertTrue(CatchException.caughtException() instanceof ValidationException);
59 }
60
61 /**
62 * Throw or inform with warnings.
63 */
64 @Test
65 void throwOrInformWithWarnings() {
66 this.createValidationErrors(new ValidationError(Level.WARN, "error1"),
67 new ValidationError(Level.WARN, "error2")).throwOrInform(this.logMock);
68 Mockito.verify(this.logMock, Mockito.times(2)).warn(ArgumentMatchers.any(CharSequence.class));
69 }
70
71 /**
72 * Creates the validation errors.
73 *
74 * @param errors
75 * the errors
76 *
77 * @return the validation errors
78 */
79 private ValidationErrors createValidationErrors(final ValidationError... errors) {
80 final var validationErrors = new ValidationErrors();
81 Collections.addAll(validationErrors, errors);
82 return validationErrors;
83 }
84
85 }