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