Skip to content

Commit 0eba29f

Browse files
committed
Add missing CheckReturnValue annotations to assertions package
1 parent b3cddef commit 0eba29f

12 files changed

+95
-2
lines changed

java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/AbstractContainerGroupAssert.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.github.ascopes.jct.containers.ContainerGroup;
2222
import java.util.ArrayList;
2323
import java.util.List;
24+
import javax.annotation.CheckReturnValue;
2425
import javax.annotation.Nullable;
2526
import javax.annotation.concurrent.NotThreadSafe;
2627
import org.apiguardian.api.API;
@@ -67,6 +68,7 @@ protected AbstractContainerGroupAssert(@Nullable C containerGroup, Class<?> self
6768
* @return the assertions to perform.
6869
* @throws AssertionError if the object being asserted upon is null.
6970
*/
71+
@CheckReturnValue
7072
public LocationAssert location() {
7173
isNotNull();
7274
return new LocationAssert(actual.getLocation());
@@ -81,6 +83,7 @@ public LocationAssert location() {
8183
* @throws AssertionError if the object being asserted upon is null.
8284
* @throws NullPointerException if the provided class parameter is null.
8385
*/
86+
@CheckReturnValue
8487
public <T> AbstractListAssert<?, List<? extends T>, T, ? extends ObjectAssert<T>> services(
8588
Class<T> clazz
8689
) {

java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/AbstractJavaFileObjectAssert.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.nio.charset.CharsetDecoder;
2727
import java.nio.charset.StandardCharsets;
2828
import java.time.Instant;
29+
import javax.annotation.CheckReturnValue;
2930
import javax.annotation.Nullable;
3031
import javax.annotation.concurrent.NotThreadSafe;
3132
import javax.tools.JavaFileObject;
@@ -66,6 +67,7 @@ protected AbstractJavaFileObjectAssert(@Nullable A actual, Class<?> selfType) {
6667
* @return the URI assertion.
6768
* @throws AssertionError if the actual value is null.
6869
*/
70+
@CheckReturnValue
6971
public AbstractUriAssert<?> uri() {
7072
isNotNull();
7173
return assertThat(actual.toUri());
@@ -77,6 +79,7 @@ public AbstractUriAssert<?> uri() {
7779
* @return the string assertion.
7880
* @throws AssertionError if the actual value is null.
7981
*/
82+
@CheckReturnValue
8083
public AbstractStringAssert<?> name() {
8184
isNotNull();
8285
return assertThat(actual.getName());
@@ -88,6 +91,7 @@ public AbstractStringAssert<?> name() {
8891
* @return the byte array assertion.
8992
* @throws AssertionError if the actual value is null.
9093
*/
94+
@CheckReturnValue
9195
public AbstractByteArrayAssert<?> binaryContent() {
9296
isNotNull();
9397
return assertThat(rawContent());
@@ -101,6 +105,7 @@ public AbstractByteArrayAssert<?> binaryContent() {
101105
* @throws AssertionError if the actual value is null.
102106
* @throws UncheckedIOException if an IO error occurs reading the file content.
103107
*/
108+
@CheckReturnValue
104109
public AbstractStringAssert<?> content() {
105110
return content(StandardCharsets.UTF_8);
106111
}
@@ -114,6 +119,7 @@ public AbstractStringAssert<?> content() {
114119
* @throws NullPointerException if the charset parameter is null.
115120
* @throws UncheckedIOException if an IO error occurs reading the file content.
116121
*/
122+
@CheckReturnValue
117123
public AbstractStringAssert<?> content(Charset charset) {
118124
requireNonNull(charset, "charset must not be null");
119125
return content(charset.newDecoder());
@@ -128,6 +134,7 @@ public AbstractStringAssert<?> content(Charset charset) {
128134
* @throws NullPointerException if the charset decoder parameter is null.
129135
* @throws UncheckedIOException if an IO error occurs reading the file content.
130136
*/
137+
@CheckReturnValue
131138
public AbstractStringAssert<?> content(CharsetDecoder charsetDecoder) {
132139
requireNonNull(charsetDecoder, "charsetDecoder must not be null");
133140
isNotNull();
@@ -148,6 +155,7 @@ public AbstractStringAssert<?> content(CharsetDecoder charsetDecoder) {
148155
* @return the instant assertion.
149156
* @throws AssertionError if the actual value is null.
150157
*/
158+
@CheckReturnValue
151159
public AbstractInstantAssert<?> lastModified() {
152160
isNotNull();
153161

@@ -161,6 +169,7 @@ public AbstractInstantAssert<?> lastModified() {
161169
* @return the assertions for the kind.
162170
* @throws AssertionError if the actual value is null.
163171
*/
172+
@CheckReturnValue
164173
public JavaFileObjectKindAssert kind() {
165174
isNotNull();
166175

java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/JavaFileObjectKindAssert.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
1919

20+
import javax.annotation.CheckReturnValue;
2021
import javax.annotation.Nullable;
2122
import javax.annotation.concurrent.NotThreadSafe;
2223
import javax.tools.JavaFileObject.Kind;
@@ -90,6 +91,7 @@ public JavaFileObjectKindAssert isOther() {
9091
* @return the assertions for the file extension of the kind.
9192
* @throws AssertionError if the kind is null.
9293
*/
94+
@CheckReturnValue
9395
public AbstractStringAssert<?> extension() {
9496
isNotNull();
9597

java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/JctAssertions.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.github.ascopes.jct.filemanagers.PathFileObject;
2424
import io.github.ascopes.jct.utils.UtilityClass;
2525
import java.util.List;
26+
import javax.annotation.CheckReturnValue;
2627
import javax.annotation.Nullable;
2728
import javax.annotation.concurrent.Immutable;
2829
import javax.annotation.concurrent.ThreadSafe;
@@ -57,6 +58,7 @@ private JctAssertions() {
5758
* @param compilation the compilation to assert on.
5859
* @return the assertion.
5960
*/
61+
@CheckReturnValue
6062
public static JctCompilationAssert assertThat(@Nullable JctCompilation compilation) {
6163
return assertThatCompilation(compilation);
6264
}
@@ -71,6 +73,7 @@ public static JctCompilationAssert assertThat(@Nullable JctCompilation compilati
7173
* @param moduleContainerGroup the module container group to assert on.
7274
* @return the assertion.
7375
*/
76+
@CheckReturnValue
7477
public static ModuleContainerGroupAssert assertThat(
7578
@Nullable ModuleContainerGroup moduleContainerGroup
7679
) {
@@ -87,6 +90,7 @@ public static ModuleContainerGroupAssert assertThat(
8790
* @param outputContainerGroup the output container group to assert on.
8891
* @return the assertion.
8992
*/
93+
@CheckReturnValue
9094
public static OutputContainerGroupAssert assertThat(
9195
@Nullable OutputContainerGroup outputContainerGroup
9296
) {
@@ -103,6 +107,7 @@ public static OutputContainerGroupAssert assertThat(
103107
* @param packageContainerGroup the package container group to assert on.
104108
* @return the assertion.
105109
*/
110+
@CheckReturnValue
106111
public static PackageContainerGroupAssert assertThat(
107112
@Nullable PackageContainerGroup packageContainerGroup
108113
) {
@@ -119,6 +124,7 @@ public static PackageContainerGroupAssert assertThat(
119124
* @param diagnostic the diagnostic to assert on.
120125
* @return the assertion.
121126
*/
127+
@CheckReturnValue
122128
public static TraceDiagnosticAssert assertThat(
123129
@Nullable TraceDiagnostic<? extends JavaFileObject> diagnostic
124130
) {
@@ -135,6 +141,7 @@ public static TraceDiagnosticAssert assertThat(
135141
* @param fileObject the file object to assert on.
136142
* @return the assertion.
137143
*/
144+
@CheckReturnValue
138145
public static JavaFileObjectAssert assertThat(@Nullable JavaFileObject fileObject) {
139146
return assertThatFileObject(fileObject);
140147
}
@@ -149,6 +156,7 @@ public static JavaFileObjectAssert assertThat(@Nullable JavaFileObject fileObjec
149156
* @param fileObject the file object to assert on.
150157
* @return the assertion.
151158
*/
159+
@CheckReturnValue
152160
public static PathFileObjectAssert assertThat(@Nullable PathFileObject fileObject) {
153161
return assertThatFileObject(fileObject);
154162
}
@@ -163,6 +171,7 @@ public static PathFileObjectAssert assertThat(@Nullable PathFileObject fileObjec
163171
* @param kind the diagnostic kind to assert on.
164172
* @return the assertion.
165173
*/
174+
@CheckReturnValue
166175
public static DiagnosticKindAssert assertThat(@Nullable Diagnostic.Kind kind) {
167176
return assertThatKind(kind);
168177
}
@@ -177,6 +186,7 @@ public static DiagnosticKindAssert assertThat(@Nullable Diagnostic.Kind kind) {
177186
* @param kind the Java file object kind to assert on.
178187
* @return the assertion.
179188
*/
189+
@CheckReturnValue
180190
public static JavaFileObjectKindAssert assertThat(@Nullable JavaFileObject.Kind kind) {
181191
return assertThatKind(kind);
182192
}
@@ -191,6 +201,7 @@ public static JavaFileObjectKindAssert assertThat(@Nullable JavaFileObject.Kind
191201
* @param location the location to assert on.
192202
* @return the assertion.
193203
*/
204+
@CheckReturnValue
194205
public static LocationAssert assertThat(@Nullable Location location) {
195206
return assertThatLocation(location);
196207
}
@@ -201,6 +212,7 @@ public static LocationAssert assertThat(@Nullable Location location) {
201212
* @param compilation the compilation to assert on.
202213
* @return the assertion.
203214
*/
215+
@CheckReturnValue
204216
public static JctCompilationAssert assertThatCompilation(@Nullable JctCompilation compilation) {
205217
return new JctCompilationAssert(compilation);
206218
}
@@ -211,6 +223,7 @@ public static JctCompilationAssert assertThatCompilation(@Nullable JctCompilatio
211223
* @param moduleContainerGroup the module container group to assert on.
212224
* @return the assertion.
213225
*/
226+
@CheckReturnValue
214227
public static ModuleContainerGroupAssert assertThatContainerGroup(
215228
@Nullable ModuleContainerGroup moduleContainerGroup
216229
) {
@@ -223,6 +236,7 @@ public static ModuleContainerGroupAssert assertThatContainerGroup(
223236
* @param outputContainerGroup the output container group to assert on.
224237
* @return the assertion.
225238
*/
239+
@CheckReturnValue
226240
public static OutputContainerGroupAssert assertThatContainerGroup(
227241
@Nullable OutputContainerGroup outputContainerGroup
228242
) {
@@ -235,6 +249,7 @@ public static OutputContainerGroupAssert assertThatContainerGroup(
235249
* @param packageContainerGroup the package container group to assert on.
236250
* @return the assertion.
237251
*/
252+
@CheckReturnValue
238253
public static PackageContainerGroupAssert assertThatContainerGroup(
239254
@Nullable PackageContainerGroup packageContainerGroup
240255
) {
@@ -247,6 +262,7 @@ public static PackageContainerGroupAssert assertThatContainerGroup(
247262
* @param diagnostic the diagnostic to assert on.
248263
* @return the assertion.
249264
*/
265+
@CheckReturnValue
250266
public static TraceDiagnosticAssert assertThatDiagnostic(
251267
@Nullable TraceDiagnostic<? extends JavaFileObject> diagnostic
252268
) {
@@ -259,6 +275,7 @@ public static TraceDiagnosticAssert assertThatDiagnostic(
259275
* @param diagnostics the diagnostics to assert on.
260276
* @return the assertion.
261277
*/
278+
@CheckReturnValue
262279
public static TraceDiagnosticListAssert assertThatDiagnostics(
263280
@Nullable List<? extends TraceDiagnostic<? extends JavaFileObject>> diagnostics
264281
) {
@@ -271,6 +288,7 @@ public static TraceDiagnosticListAssert assertThatDiagnostics(
271288
* @param fileObject the file object to assert on.
272289
* @return the assertion.
273290
*/
291+
@CheckReturnValue
274292
public static JavaFileObjectAssert assertThatFileObject(@Nullable JavaFileObject fileObject) {
275293
return new JavaFileObjectAssert(fileObject);
276294
}
@@ -281,6 +299,7 @@ public static JavaFileObjectAssert assertThatFileObject(@Nullable JavaFileObject
281299
* @param fileObject the file object to assert on.
282300
* @return the assertion.
283301
*/
302+
@CheckReturnValue
284303
public static PathFileObjectAssert assertThatFileObject(@Nullable PathFileObject fileObject) {
285304
return new PathFileObjectAssert(fileObject);
286305
}
@@ -291,6 +310,7 @@ public static PathFileObjectAssert assertThatFileObject(@Nullable PathFileObject
291310
* @param kind the diagnostic kind to assert on.
292311
* @return the assertion.
293312
*/
313+
@CheckReturnValue
294314
public static DiagnosticKindAssert assertThatKind(@Nullable Diagnostic.Kind kind) {
295315
return new DiagnosticKindAssert(kind);
296316
}
@@ -301,6 +321,7 @@ public static DiagnosticKindAssert assertThatKind(@Nullable Diagnostic.Kind kind
301321
* @param kind the Java file object kind to assert on.
302322
* @return the assertion.
303323
*/
324+
@CheckReturnValue
304325
public static JavaFileObjectKindAssert assertThatKind(@Nullable JavaFileObject.Kind kind) {
305326
return new JavaFileObjectKindAssert(kind);
306327
}
@@ -311,6 +332,7 @@ public static JavaFileObjectKindAssert assertThatKind(@Nullable JavaFileObject.K
311332
* @param location the location to assert on.
312333
* @return the assertion.
313334
*/
335+
@CheckReturnValue
314336
public static LocationAssert assertThatLocation(@Nullable Location location) {
315337
return new LocationAssert(location);
316338
}

java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/JctCompilationAssert.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.github.ascopes.jct.compilers.JctCompilation;
2222
import io.github.ascopes.jct.repr.DiagnosticListRepresentation;
2323
import java.util.Collection;
24+
import javax.annotation.CheckReturnValue;
2425
import javax.annotation.Nullable;
2526
import javax.annotation.concurrent.NotThreadSafe;
2627
import javax.tools.Diagnostic.Kind;
@@ -117,6 +118,7 @@ public JctCompilationAssert isFailure() {
117118
* @return assertions for the diagnostics.
118119
* @throws AssertionError if the compilation was null.
119120
*/
121+
@CheckReturnValue
120122
public TraceDiagnosticListAssert diagnostics() {
121123
isNotNull();
122124
return new TraceDiagnosticListAssert(actual.getDiagnostics());
@@ -134,6 +136,7 @@ public TraceDiagnosticListAssert diagnostics() {
134136
* {@link Location#isModuleOrientedLocation() module-oriented}.
135137
* @throws NullPointerException if the provided location object is null.
136138
*/
139+
@CheckReturnValue
137140
public PackageContainerGroupAssert packageGroup(Location location) {
138141
requireNonNull(location, "location must not be null");
139142

@@ -162,6 +165,7 @@ public PackageContainerGroupAssert packageGroup(Location location) {
162165
* {@link Location#isModuleOrientedLocation() module-oriented}.
163166
* @throws NullPointerException if the provided location object is null.
164167
*/
168+
@CheckReturnValue
165169
public ModuleContainerGroupAssert moduleGroup(Location location) {
166170
requireNonNull(location, "location must not be null");
167171

@@ -190,6 +194,7 @@ public ModuleContainerGroupAssert moduleGroup(Location location) {
190194
* {@link Location#isOutputLocation() an output location}.
191195
* @throws NullPointerException if the provided location object is null.
192196
*/
197+
@CheckReturnValue
193198
public OutputContainerGroupAssert outputGroup(Location location) {
194199
requireNonNull(location, "location must not be null");
195200

@@ -214,6 +219,7 @@ public OutputContainerGroupAssert outputGroup(Location location) {
214219
* @return the assertions to perform on the class outputs.
215220
* @throws AssertionError if the compilation is null.
216221
*/
222+
@CheckReturnValue
217223
public OutputContainerGroupAssert classOutput() {
218224
return outputGroup(StandardLocation.CLASS_OUTPUT);
219225
}
@@ -226,6 +232,7 @@ public OutputContainerGroupAssert classOutput() {
226232
* @return the assertions to perform on the source outputs.
227233
* @throws AssertionError if the compilation is null.
228234
*/
235+
@CheckReturnValue
229236
public OutputContainerGroupAssert sourceOutput() {
230237
return outputGroup(StandardLocation.SOURCE_OUTPUT);
231238
}
@@ -238,6 +245,7 @@ public OutputContainerGroupAssert sourceOutput() {
238245
* @return the assertions to perform on the header outputs.
239246
* @throws AssertionError if the compilation is null.
240247
*/
248+
@CheckReturnValue
241249
public OutputContainerGroupAssert generatedHeaders() {
242250
return outputGroup(StandardLocation.NATIVE_HEADER_OUTPUT);
243251
}
@@ -250,6 +258,7 @@ public OutputContainerGroupAssert generatedHeaders() {
250258
* @return the assertions to perform on the class path.
251259
* @throws AssertionError if the compilation is null.
252260
*/
261+
@CheckReturnValue
253262
public PackageContainerGroupAssert classPath() {
254263
return packageGroup(StandardLocation.CLASS_PATH);
255264
}
@@ -262,6 +271,7 @@ public PackageContainerGroupAssert classPath() {
262271
* @return the assertions to perform on the source path.
263272
* @throws AssertionError if the compilation is null.
264273
*/
274+
@CheckReturnValue
265275
public PackageContainerGroupAssert sourcePath() {
266276
return packageGroup(StandardLocation.SOURCE_PATH);
267277
}
@@ -274,6 +284,7 @@ public PackageContainerGroupAssert sourcePath() {
274284
* @return the assertions to perform on the source path.
275285
* @throws AssertionError if the compilation is null.
276286
*/
287+
@CheckReturnValue
277288
public ModuleContainerGroupAssert moduleSourcePath() {
278289
return moduleGroup(StandardLocation.MODULE_SOURCE_PATH);
279290
}
@@ -286,6 +297,7 @@ public ModuleContainerGroupAssert moduleSourcePath() {
286297
* @return the assertions to perform on the module path.
287298
* @throws AssertionError if the compilation is null.
288299
*/
300+
@CheckReturnValue
289301
public ModuleContainerGroupAssert modulePath() {
290302
return moduleGroup(StandardLocation.MODULE_PATH);
291303
}

java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/LocationAssert.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.assertj.core.api.Assertions.assertThat;
1919

2020
import io.github.ascopes.jct.repr.LocationRepresentation;
21+
import javax.annotation.CheckReturnValue;
2122
import javax.annotation.Nullable;
2223
import javax.annotation.concurrent.NotThreadSafe;
2324
import javax.tools.JavaFileManager.Location;
@@ -124,6 +125,7 @@ public LocationAssert isNotOutputLocation() {
124125
* @return the string assertions to perform.
125126
* @throws AssertionError if the location is null.
126127
*/
128+
@CheckReturnValue
127129
public AbstractStringAssert<?> name() {
128130
isNotNull();
129131

0 commit comments

Comments
 (0)