Skip to content

Commit eb4bf78

Browse files
committed
DiagnosticKindAssert tests
1 parent ec2289d commit eb4bf78

File tree

1 file changed

+213
-0
lines changed

1 file changed

+213
-0
lines changed
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
/*
2+
* Copyright (C) 2022 - 2023, the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.github.ascopes.jct.tests.unit.assertions;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
20+
21+
import io.github.ascopes.jct.assertions.DiagnosticKindAssert;
22+
import javax.tools.Diagnostic.Kind;
23+
import org.junit.jupiter.api.DisplayName;
24+
import org.junit.jupiter.api.Nested;
25+
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.params.ParameterizedTest;
27+
import org.junit.jupiter.params.provider.EnumSource;
28+
import org.junit.jupiter.params.provider.EnumSource.Mode;
29+
import org.junit.jupiter.params.provider.NullSource;
30+
31+
/**
32+
* {@link DiagnosticKindAssert} tests.
33+
*
34+
* @author Ashley Scopes
35+
*/
36+
@DisplayName("DiagnosticKindAssert tests")
37+
class DiagnosticKindAssertTest {
38+
39+
@DisplayName("DiagnosticKindAssert#isError tests")
40+
@Nested
41+
class IsErrorTest {
42+
43+
@DisplayName(".isError() fails if the kind is not an error")
44+
@NullSource
45+
@EnumSource(value = Kind.class, mode = Mode.EXCLUDE, names = "ERROR")
46+
@ParameterizedTest(name = "for {0}")
47+
void isErrorFailsIfKindIsNotError(Kind kind) {
48+
// Given
49+
var assertions = new DiagnosticKindAssert(kind);
50+
51+
// Then
52+
assertThatThrownBy(assertions::isError)
53+
.isInstanceOf(AssertionError.class);
54+
}
55+
56+
@DisplayName(".isError() succeeds if the kind is an error")
57+
@Test
58+
void isErrorSucceedsIfTheKindIsAnError() {
59+
// Given
60+
var assertions = new DiagnosticKindAssert(Kind.ERROR);
61+
62+
// Then
63+
assertThat(assertions.isError())
64+
.isSameAs(assertions);
65+
}
66+
}
67+
68+
@DisplayName("DiagnosticKindAssert#isWarning tests")
69+
@Nested
70+
class IsWarningTest {
71+
72+
@DisplayName(".isWarning() fails if the kind is not a warning or mandatory warning")
73+
@NullSource
74+
@EnumSource(value = Kind.class, mode = Mode.EXCLUDE, names = {"WARNING", "MANDATORY_WARNING"})
75+
@ParameterizedTest(name = "for {0}")
76+
void isWarningFailsIfKindIsNotWarning(Kind kind) {
77+
// Given
78+
var assertions = new DiagnosticKindAssert(kind);
79+
80+
// Then
81+
assertThatThrownBy(assertions::isWarning)
82+
.isInstanceOf(AssertionError.class);
83+
}
84+
85+
@DisplayName(".isWarning() succeeds if the kind is a warning or mandatory warning")
86+
@EnumSource(value = Kind.class, mode = Mode.INCLUDE, names = {"WARNING", "MANDATORY_WARNING"})
87+
@ParameterizedTest(name = "for {0}")
88+
void isWarningSucceedsIfTheKindIsWarning(Kind kind) {
89+
// Given
90+
var assertions = new DiagnosticKindAssert(kind);
91+
92+
// Then
93+
assertThat(assertions.isWarning())
94+
.isSameAs(assertions);
95+
}
96+
}
97+
98+
@DisplayName("DiagnosticKindAssert#isCustomWarning tests")
99+
@Nested
100+
class IsCustomWarningTest {
101+
102+
@DisplayName(".isCustomWarning() fails if the kind is not WARNING")
103+
@NullSource
104+
@EnumSource(value = Kind.class, mode = Mode.EXCLUDE, names = "WARNING")
105+
@ParameterizedTest(name = "for {0}")
106+
void isCustomWarningFailsIfKindIsNotCustomWarning(Kind kind) {
107+
// Given
108+
var assertions = new DiagnosticKindAssert(kind);
109+
110+
// Then
111+
assertThatThrownBy(assertions::isCustomWarning)
112+
.isInstanceOf(AssertionError.class);
113+
}
114+
115+
@DisplayName(".isCustomWarning() succeeds if the kind is WARNING")
116+
@Test
117+
void isCustomWarningSucceedsIfTheKindIsCustomWarning() {
118+
// Given
119+
var assertions = new DiagnosticKindAssert(Kind.WARNING);
120+
121+
// Then
122+
assertThat(assertions.isCustomWarning())
123+
.isSameAs(assertions);
124+
}
125+
}
126+
127+
@DisplayName("DiagnosticKindAssert#isMandatoryWarning tests")
128+
@Nested
129+
class IsMandatoryWarningTest {
130+
131+
@DisplayName(".isMandatoryWarning() fails if the kind is not a mandatory warning")
132+
@NullSource
133+
@EnumSource(value = Kind.class, mode = Mode.EXCLUDE, names = "MANDATORY_WARNING")
134+
@ParameterizedTest(name = "for {0}")
135+
void isMandatoryWarningFailsIfKindIsNotMandatoryWarning(Kind kind) {
136+
// Given
137+
var assertions = new DiagnosticKindAssert(kind);
138+
139+
// Then
140+
assertThatThrownBy(assertions::isMandatoryWarning)
141+
.isInstanceOf(AssertionError.class);
142+
}
143+
144+
@DisplayName(".isMandatoryWarning() succeeds if the kind is a mandatory warning")
145+
@Test
146+
void isMandatoryWarningSucceedsIfTheKindIsMandatoryWarning() {
147+
// Given
148+
var assertions = new DiagnosticKindAssert(Kind.MANDATORY_WARNING);
149+
150+
// Then
151+
assertThat(assertions.isMandatoryWarning())
152+
.isSameAs(assertions);
153+
}
154+
}
155+
156+
@DisplayName("DiagnosticKindAssert#isNote tests")
157+
@Nested
158+
class IsNoteTest {
159+
160+
@DisplayName(".isNote() fails if the kind is not a note")
161+
@NullSource
162+
@EnumSource(value = Kind.class, mode = Mode.EXCLUDE, names = "NOTE")
163+
@ParameterizedTest(name = "for {0}")
164+
void isNoteFailsIfKindIsNotNote(Kind kind) {
165+
// Given
166+
var assertions = new DiagnosticKindAssert(kind);
167+
168+
// Then
169+
assertThatThrownBy(assertions::isNote)
170+
.isInstanceOf(AssertionError.class);
171+
}
172+
173+
@DisplayName(".isNote() succeeds if the kind is a note")
174+
@Test
175+
void isNoteSucceedsIfTheKindIsNote() {
176+
// Given
177+
var assertions = new DiagnosticKindAssert(Kind.NOTE);
178+
179+
// Then
180+
assertThat(assertions.isNote())
181+
.isSameAs(assertions);
182+
}
183+
}
184+
185+
@DisplayName("DiagnosticKindAssert#isOther tests")
186+
@Nested
187+
class IsOtherTest {
188+
189+
@DisplayName(".isOther() fails if the kind is not OTHER")
190+
@NullSource
191+
@EnumSource(value = Kind.class, mode = Mode.EXCLUDE, names = "OTHER")
192+
@ParameterizedTest(name = "for {0}")
193+
void isOtherFailsIfKindIsNotOther(Kind kind) {
194+
// Given
195+
var assertions = new DiagnosticKindAssert(kind);
196+
197+
// Then
198+
assertThatThrownBy(assertions::isOther)
199+
.isInstanceOf(AssertionError.class);
200+
}
201+
202+
@DisplayName(".isOther() succeeds if the kind is OTHER")
203+
@Test
204+
void isOtherSucceedsIfTheKindIsOther() {
205+
// Given
206+
var assertions = new DiagnosticKindAssert(Kind.OTHER);
207+
208+
// Then
209+
assertThat(assertions.isOther())
210+
.isSameAs(assertions);
211+
}
212+
}
213+
}

0 commit comments

Comments
 (0)