Skip to content

Commit cb0fd29

Browse files
committed
JavaFileObjectKindAssert tests
1 parent df35be5 commit cb0fd29

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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.JavaFileObjectKindAssert;
22+
import javax.tools.JavaFileObject.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 JavaFileObjectKindAssert} tests.
33+
*
34+
* @author Ashley Scopes
35+
*/
36+
@DisplayName("JavaFileObjectKindAssert tests")
37+
class JavaFileObjectKindAssertTest {
38+
39+
@DisplayName("JavaFileObjectKindAssert#isSource tests")
40+
@Nested
41+
class IsSourceTest {
42+
43+
@DisplayName(".isSource() fails if the kind is not a source")
44+
@NullSource
45+
@EnumSource(value = Kind.class, mode = Mode.EXCLUDE, names = "SOURCE")
46+
@ParameterizedTest(name = "for {0}")
47+
void isSourceFailsIfKindIsNotSource(Kind kind) {
48+
// Given
49+
var assertions = new JavaFileObjectKindAssert(kind);
50+
51+
// Then
52+
assertThatThrownBy(assertions::isSource)
53+
.isInstanceOf(AssertionError.class);
54+
}
55+
56+
@DisplayName(".isSource() succeeds if the kind is a source")
57+
@Test
58+
void isSourceSucceedsIfTheKindIsSource() {
59+
// Given
60+
var assertions = new JavaFileObjectKindAssert(Kind.SOURCE);
61+
62+
// Then
63+
assertThat(assertions.isSource())
64+
.isSameAs(assertions);
65+
}
66+
}
67+
68+
@DisplayName("JavaFileObjectKindAssert#isClass tests")
69+
@Nested
70+
class IsClassTest {
71+
72+
@DisplayName(".isClass() fails if the kind is not a class")
73+
@NullSource
74+
@EnumSource(value = Kind.class, mode = Mode.EXCLUDE, names = "CLASS")
75+
@ParameterizedTest(name = "for {0}")
76+
void isClassFailsIfKindIsNotClass(Kind kind) {
77+
// Given
78+
var assertions = new JavaFileObjectKindAssert(kind);
79+
80+
// Then
81+
assertThatThrownBy(assertions::isClass)
82+
.isInstanceOf(AssertionError.class);
83+
}
84+
85+
@DisplayName(".isClass() succeeds if the kind is a class")
86+
@Test
87+
void isClassSucceedsIfTheKindIsClass() {
88+
// Given
89+
var assertions = new JavaFileObjectKindAssert(Kind.CLASS);
90+
91+
// Then
92+
assertThat(assertions.isClass())
93+
.isSameAs(assertions);
94+
}
95+
}
96+
97+
@DisplayName("JavaFileObjectKindAssert#isHtml tests")
98+
@Nested
99+
class IsHtmlTest {
100+
101+
@DisplayName(".isHtml() fails if the kind is not HTML")
102+
@NullSource
103+
@EnumSource(value = Kind.class, mode = Mode.EXCLUDE, names = "HTML")
104+
@ParameterizedTest(name = "for {0}")
105+
void isHtmlFailsIfKindIsNotHtml(Kind kind) {
106+
// Given
107+
var assertions = new JavaFileObjectKindAssert(kind);
108+
109+
// Then
110+
assertThatThrownBy(assertions::isHtml)
111+
.isInstanceOf(AssertionError.class);
112+
}
113+
114+
@DisplayName(".isHtml() succeeds if the kind is HTML")
115+
@Test
116+
void isHtmlSucceedsIfTheKindIsHtml() {
117+
// Given
118+
var assertions = new JavaFileObjectKindAssert(Kind.HTML);
119+
120+
// Then
121+
assertThat(assertions.isHtml())
122+
.isSameAs(assertions);
123+
}
124+
}
125+
126+
@DisplayName("JavaFileObjectKindAssert#isOther tests")
127+
@Nested
128+
class IsOtherTest {
129+
130+
@DisplayName(".isOther() fails if the kind is not OTHER")
131+
@NullSource
132+
@EnumSource(value = Kind.class, mode = Mode.EXCLUDE, names = "OTHER")
133+
@ParameterizedTest(name = "for {0}")
134+
void isOtherFailsIfKindIsNotOther(Kind kind) {
135+
// Given
136+
var assertions = new JavaFileObjectKindAssert(kind);
137+
138+
// Then
139+
assertThatThrownBy(assertions::isOther)
140+
.isInstanceOf(AssertionError.class);
141+
}
142+
143+
@DisplayName(".isOther() succeeds if the kind is OTHER")
144+
@Test
145+
void isOtherSucceedsIfTheKindIsOther() {
146+
// Given
147+
var assertions = new JavaFileObjectKindAssert(Kind.OTHER);
148+
149+
// Then
150+
assertThat(assertions.isOther())
151+
.isSameAs(assertions);
152+
}
153+
}
154+
}

0 commit comments

Comments
 (0)