All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.ascopes.jct.assertions.DiagnosticKindAssert Maven / Gradle / Ivy

Go to download

Library to help developers write declarative integration tests that call the Java Compiler toolchain.

There is a newer version: 4.0.3
Show newest version
/*
 * Copyright (C) 2022 - 2024, the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.github.ascopes.jct.assertions;

import java.util.EnumSet;
import java.util.Set;
import javax.tools.Diagnostic.Kind;
import org.jspecify.annotations.Nullable;

/**
 * Assertions for an individual diagnostic kind.
 *
 * @author Ashley Scopes
 * @since 0.0.1
 */
public final class DiagnosticKindAssert
    extends AbstractEnumAssert {

  /**
   * Kinds that we consider to be types of warnings.
   */
  static final Set WARNING_DIAGNOSTIC_KINDS = EnumSet.of(
      Kind.WARNING,
      Kind.MANDATORY_WARNING
  );

  /**
   * Kinds that we consider to be types of error.
   */
  static final Set ERROR_DIAGNOSTIC_KINDS = EnumSet.of(
      Kind.ERROR
  );

  /**
   * Kinds that we consider to be types of warning or errors.
   */
  static final Set WARNING_AND_ERROR_DIAGNOSTIC_KINDS = EnumSet.of(
      Kind.WARNING,
      Kind.MANDATORY_WARNING,
      Kind.ERROR
  );

  /**
   * Initialize this assertion type.
   *
   * @param value the value to assert on.
   */
  public DiagnosticKindAssert(@Nullable Kind value) {
    super(value, DiagnosticKindAssert.class);
  }

  /**
   * Assert that the kind is {@link Kind#ERROR}.
   *
   * @return this assertion object.
   * @throws AssertionError if this value is null, or the value is not {@link Kind#ERROR}.
   */
  public DiagnosticKindAssert isError() {
    return isAnyOfElements(ERROR_DIAGNOSTIC_KINDS);
  }

  /**
   * Assert that the kind is {@link Kind#ERROR}, {@link Kind#WARNING}, or
   * {@link Kind#MANDATORY_WARNING}.
   *
   * @return this assertion object.
   * @throws AssertionError if this value is null, or the value is not any of {@link Kind#ERROR},
   *                        {@link Kind#WARNING}, or {@link Kind#MANDATORY_WARNING}.
   */
  public DiagnosticKindAssert isWarningOrError() {
    return isAnyOfElements(WARNING_AND_ERROR_DIAGNOSTIC_KINDS);
  }

  /**
   * Assert that the kind is either {@link Kind#WARNING} or {@link Kind#MANDATORY_WARNING}.
   *
   * @return this assertion object.
   * @throws AssertionError if this value is null, or the value is not either {@link Kind#WARNING}
   *                        or {@link Kind#MANDATORY_WARNING}.
   */
  public DiagnosticKindAssert isWarning() {
    return isAnyOfElements(WARNING_DIAGNOSTIC_KINDS);
  }

  /**
   * Assert that the kind is {@link Kind#WARNING}.
   *
   * @return this assertion object.
   * @throws AssertionError if this value is null, or the value is not {@link Kind#WARNING}.
   */
  public DiagnosticKindAssert isCustomWarning() {
    return isAnyOf(Kind.WARNING);
  }

  /**
   * Assert that the kind is {@link Kind#MANDATORY_WARNING}.
   *
   * @return this assertion object.
   * @throws AssertionError if this value is null, or the value is not
   *                        {@link Kind#MANDATORY_WARNING}.
   */
  public DiagnosticKindAssert isMandatoryWarning() {
    return isAnyOf(Kind.MANDATORY_WARNING);
  }

  /**
   * Assert that the kind is {@link Kind#NOTE}.
   *
   * @return this assertion object.
   * @throws AssertionError if this value is null, or the value is not {@link Kind#NOTE}.
   */
  public DiagnosticKindAssert isNote() {
    return isAnyOf(Kind.NOTE);
  }

  /**
   * Assert that the kind is {@link Kind#OTHER}.
   *
   * @return this assertion object.
   * @throws AssertionError if this value is null, or the value is not {@link Kind#OTHER}.
   */
  public DiagnosticKindAssert isOther() {
    return isAnyOf(Kind.OTHER);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy