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 static org.assertj.core.api.Assertions.assertThat; 019 020import javax.tools.JavaFileObject.Kind; 021import org.apiguardian.api.API; 022import org.apiguardian.api.API.Status; 023import org.assertj.core.api.AbstractStringAssert; 024import org.jspecify.annotations.Nullable; 025 026/** 027 * Assertions for an individual {@link Kind Java file object kind}. 028 * 029 * @author Ashley Scopes 030 * @since 0.0.1 031 */ 032@API(since = "0.0.1", status = Status.STABLE) 033public final class JavaFileObjectKindAssert 034 extends AbstractEnumAssert<JavaFileObjectKindAssert, Kind> { 035 036 /** 037 * Initialize this assertion type. 038 * 039 * @param value the value to assert on. 040 */ 041 public JavaFileObjectKindAssert(@Nullable Kind value) { 042 super(value, JavaFileObjectKindAssert.class); 043 } 044 045 /** 046 * Assert that the kind is a {@link Kind#SOURCE}. 047 * 048 * @return this assertion object. 049 * @throws AssertionError if the kind is null. 050 */ 051 public JavaFileObjectKindAssert isSource() { 052 return isAnyOf(Kind.SOURCE); 053 } 054 055 /** 056 * Assert that the kind is a {@link Kind#CLASS}. 057 * 058 * @return this assertion object. 059 * @throws AssertionError if the kind is null. 060 */ 061 public JavaFileObjectKindAssert isClass() { 062 return isAnyOf(Kind.CLASS); 063 } 064 065 /** 066 * Assert that the kind is an {@link Kind#HTML HTML source}. 067 * 068 * @return this assertion object. 069 * @throws AssertionError if the kind is null. 070 */ 071 public JavaFileObjectKindAssert isHtml() { 072 return isAnyOf(Kind.HTML); 073 } 074 075 /** 076 * Assert that the kind is {@link Kind#OTHER some other unknown kind}. 077 * 078 * @return this assertion object. 079 * @throws AssertionError if the kind is null. 080 */ 081 public JavaFileObjectKindAssert isOther() { 082 return isAnyOf(Kind.OTHER); 083 } 084 085 /** 086 * Perform an assertion on the file extension of the kind. 087 * 088 * @return the assertions for the file extension of the kind. 089 * @throws AssertionError if the kind is null. 090 */ 091 public AbstractStringAssert<?> extension() { 092 isNotNull(); 093 094 return assertThat(actual.extension); 095 } 096}