001/* 002 * Copyright (C) 2022 - 2024, the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.github.ascopes.jct.assertions; 017 018import io.github.ascopes.jct.compilers.JctCompilation; 019import io.github.ascopes.jct.containers.ModuleContainerGroup; 020import io.github.ascopes.jct.containers.OutputContainerGroup; 021import io.github.ascopes.jct.containers.PackageContainerGroup; 022import io.github.ascopes.jct.diagnostics.TraceDiagnostic; 023import io.github.ascopes.jct.filemanagers.PathFileObject; 024import io.github.ascopes.jct.utils.UtilityClass; 025import java.util.List; 026import javax.tools.Diagnostic; 027import javax.tools.JavaFileManager.Location; 028import javax.tools.JavaFileObject; 029import org.jspecify.annotations.Nullable; 030 031/** 032 * Helper class to provide fluent creation of assertions for compilations. 033 * 034 * @author Ashley Scopes 035 * @since 0.0.1 036 */ 037@SuppressWarnings("unused") 038public final class JctAssertions extends UtilityClass { 039 040 private JctAssertions() { 041 // Disallow initialisation. 042 } 043 044 /** 045 * Perform an assertion on a compilation. 046 * 047 * <p>This is a shorthand alias for {@link #assertThatCompilation(JctCompilation)}. If you are 048 * using AssertJ assertions in your tests with static imports, you may wish to use that instead to 049 * prevent name conflicts. 050 * 051 * @param compilation the compilation to assert on. 052 * @return the assertion. 053 */ 054 public static JctCompilationAssert assertThat(@Nullable JctCompilation compilation) { 055 return assertThatCompilation(compilation); 056 } 057 058 /** 059 * Perform an assertion on a module container group. 060 * 061 * <p>This is a shorthand alias for {@link #assertThatContainerGroup(ModuleContainerGroup)}. If 062 * you are using AssertJ assertions in your tests with static imports, you may wish to use that 063 * instead to prevent name conflicts. 064 * 065 * @param moduleContainerGroup the module container group to assert on. 066 * @return the assertion. 067 */ 068 public static ModuleContainerGroupAssert assertThat( 069 @Nullable ModuleContainerGroup moduleContainerGroup 070 ) { 071 return assertThatContainerGroup(moduleContainerGroup); 072 } 073 074 /** 075 * Perform an assertion on an output container group. 076 * 077 * <p>This is a shorthand alias for {@link #assertThatContainerGroup(OutputContainerGroup)}. If 078 * you are using AssertJ assertions in your tests with static imports, you may wish to use that 079 * instead to prevent name conflicts. 080 * 081 * @param outputContainerGroup the output container group to assert on. 082 * @return the assertion. 083 */ 084 public static OutputContainerGroupAssert assertThat( 085 @Nullable OutputContainerGroup outputContainerGroup 086 ) { 087 return assertThatContainerGroup(outputContainerGroup); 088 } 089 090 /** 091 * Perform an assertion on a package container group. 092 * 093 * <p>This is a shorthand alias for {@link #assertThatContainerGroup(PackageContainerGroup)}. If 094 * you are using AssertJ assertions in your tests with static imports, you may wish to use that 095 * instead to prevent name conflicts. 096 * 097 * @param packageContainerGroup the package container group to assert on. 098 * @return the assertion. 099 */ 100 public static PackageContainerGroupAssert assertThat( 101 @Nullable PackageContainerGroup packageContainerGroup 102 ) { 103 return assertThatContainerGroup(packageContainerGroup); 104 } 105 106 /** 107 * Perform an assertion on a diagnostic. 108 * 109 * <p>This is a shorthand alias for {@link #assertThatDiagnostic(TraceDiagnostic)}. If 110 * you are using AssertJ assertions in your tests with static imports, you may wish to use that 111 * instead to prevent name conflicts. 112 * 113 * @param diagnostic the diagnostic to assert on. 114 * @return the assertion. 115 */ 116 public static TraceDiagnosticAssert assertThat( 117 @Nullable TraceDiagnostic<? extends JavaFileObject> diagnostic 118 ) { 119 return assertThatDiagnostic(diagnostic); 120 } 121 122 /** 123 * Perform an assertion on a Java file object. 124 * 125 * <p>This is a shorthand alias for {@link #assertThatFileObject(JavaFileObject)}. If you are 126 * using AssertJ assertions in your tests with static imports, you may wish to use that instead to 127 * prevent name conflicts. 128 * 129 * @param fileObject the file object to assert on. 130 * @return the assertion. 131 */ 132 public static JavaFileObjectAssert assertThat(@Nullable JavaFileObject fileObject) { 133 return assertThatFileObject(fileObject); 134 } 135 136 /** 137 * Perform an assertion on a Path-based Java file object. 138 * 139 * <p>This is a shorthand alias for {@link #assertThatFileObject(PathFileObject)}. If you are 140 * using AssertJ assertions in your tests with static imports, you may wish to use that instead to 141 * prevent name conflicts. 142 * 143 * @param fileObject the file object to assert on. 144 * @return the assertion. 145 */ 146 public static PathFileObjectAssert assertThat(@Nullable PathFileObject fileObject) { 147 return assertThatFileObject(fileObject); 148 } 149 150 /** 151 * Perform an assertion on a diagnostic kind. 152 * 153 * <p>This is a shorthand alias for {@link #assertThatKind(Diagnostic.Kind)}. If you are using 154 * AssertJ assertions in your tests with static imports, you may wish to use that instead to 155 * prevent name conflicts. 156 * 157 * @param kind the diagnostic kind to assert on. 158 * @return the assertion. 159 */ 160 public static DiagnosticKindAssert assertThat(Diagnostic.@Nullable Kind kind) { 161 return assertThatKind(kind); 162 } 163 164 /** 165 * Perform an assertion on a Java file object kind. 166 * 167 * <p>This is a shorthand alias for {@link #assertThatKind(JavaFileObject.Kind)}. If you are 168 * using AssertJ assertions in your tests with static imports, you may wish to use that instead to 169 * prevent name conflicts. 170 * 171 * @param kind the Java file object kind to assert on. 172 * @return the assertion. 173 */ 174 public static JavaFileObjectKindAssert assertThat(JavaFileObject.@Nullable Kind kind) { 175 return assertThatKind(kind); 176 } 177 178 /** 179 * Perform an assertion on a location. 180 * 181 * <p>This is a shorthand alias for {@link #assertThatLocation(Location)}. If you are using 182 * AssertJ assertions in your tests with static imports, you may wish to use that instead to 183 * prevent name conflicts. 184 * 185 * @param location the location to assert on. 186 * @return the assertion. 187 */ 188 public static LocationAssert assertThat(@Nullable Location location) { 189 return assertThatLocation(location); 190 } 191 192 /** 193 * Perform an assertion on a compilation. 194 * 195 * @param compilation the compilation to assert on. 196 * @return the assertion. 197 */ 198 public static JctCompilationAssert assertThatCompilation(@Nullable JctCompilation compilation) { 199 return new JctCompilationAssert(compilation); 200 } 201 202 /** 203 * Perform an assertion on a module container group. 204 * 205 * @param moduleContainerGroup the module container group to assert on. 206 * @return the assertion. 207 */ 208 public static ModuleContainerGroupAssert assertThatContainerGroup( 209 @Nullable ModuleContainerGroup moduleContainerGroup 210 ) { 211 return new ModuleContainerGroupAssert(moduleContainerGroup); 212 } 213 214 /** 215 * Perform an assertion on an output container group. 216 * 217 * @param outputContainerGroup the output container group to assert on. 218 * @return the assertion. 219 */ 220 public static OutputContainerGroupAssert assertThatContainerGroup( 221 @Nullable OutputContainerGroup outputContainerGroup 222 ) { 223 return new OutputContainerGroupAssert(outputContainerGroup); 224 } 225 226 /** 227 * Perform an assertion on a package container group. 228 * 229 * @param packageContainerGroup the package container group to assert on. 230 * @return the assertion. 231 */ 232 public static PackageContainerGroupAssert assertThatContainerGroup( 233 @Nullable PackageContainerGroup packageContainerGroup 234 ) { 235 return new PackageContainerGroupAssert(packageContainerGroup); 236 } 237 238 /** 239 * Perform an assertion on a diagnostic. 240 * 241 * @param diagnostic the diagnostic to assert on. 242 * @return the assertion. 243 */ 244 public static TraceDiagnosticAssert assertThatDiagnostic( 245 @Nullable TraceDiagnostic<? extends JavaFileObject> diagnostic 246 ) { 247 return new TraceDiagnosticAssert(diagnostic); 248 } 249 250 /** 251 * Perform an assertion on a list of diagnostics. 252 * 253 * @param diagnostics the diagnostics to assert on. 254 * @return the assertion. 255 */ 256 public static TraceDiagnosticListAssert assertThatDiagnostics( 257 @Nullable List<? extends TraceDiagnostic<? extends JavaFileObject>> diagnostics 258 ) { 259 return new TraceDiagnosticListAssert(diagnostics); 260 } 261 262 /** 263 * Perform an assertion on a Java file object. 264 * 265 * @param fileObject the file object to assert on. 266 * @return the assertion. 267 */ 268 public static JavaFileObjectAssert assertThatFileObject(@Nullable JavaFileObject fileObject) { 269 return new JavaFileObjectAssert(fileObject); 270 } 271 272 /** 273 * Perform an assertion on a Path-based Java file object. 274 * 275 * @param fileObject the file object to assert on. 276 * @return the assertion. 277 */ 278 public static PathFileObjectAssert assertThatFileObject(@Nullable PathFileObject fileObject) { 279 return new PathFileObjectAssert(fileObject); 280 } 281 282 /** 283 * Perform an assertion on a diagnostic kind. 284 * 285 * @param kind the diagnostic kind to assert on. 286 * @return the assertion. 287 */ 288 public static DiagnosticKindAssert assertThatKind(Diagnostic.@Nullable Kind kind) { 289 return new DiagnosticKindAssert(kind); 290 } 291 292 /** 293 * Perform an assertion on a Java file object kind. 294 * 295 * @param kind the Java file object kind to assert on. 296 * @return the assertion. 297 */ 298 public static JavaFileObjectKindAssert assertThatKind(JavaFileObject.@Nullable Kind kind) { 299 return new JavaFileObjectKindAssert(kind); 300 } 301 302 /** 303 * Perform an assertion on a location. 304 * 305 * @param location the location to assert on. 306 * @return the assertion. 307 */ 308 public static LocationAssert assertThatLocation(@Nullable Location location) { 309 return new LocationAssert(location); 310 } 311} 312