Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2016-2024 Qameta Software Inc
*
* 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.qameta.allure.util;
import io.qameta.allure.Flaky;
import io.qameta.allure.LabelAnnotation;
import io.qameta.allure.LinkAnnotation;
import io.qameta.allure.Muted;
import io.qameta.allure.model.Label;
import io.qameta.allure.model.Link;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.annotation.Annotation;
import java.lang.annotation.Repeatable;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static io.qameta.allure.util.ResultsUtils.createLabel;
import static io.qameta.allure.util.ResultsUtils.createLink;
import static java.util.Arrays.asList;
/**
* Collection of utils used by Allure integration to extract meta information from
* test cases via reflection.
*
* @author charlie (Dmitry Baev).
*/
public final class AnnotationUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(AnnotationUtils.class);
private static final String VALUE_METHOD_NAME = "value";
private AnnotationUtils() {
throw new IllegalStateException("Do not instance");
}
/**
* Returns true if {@link io.qameta.allure.Flaky} annotation is present.
*
* @param annotatedElement the element to search annotations on.
* @return true if {@link io.qameta.allure.Flaky} annotation is present, false otherwise.
*/
public static boolean isFlaky(final AnnotatedElement annotatedElement) {
return annotatedElement.isAnnotationPresent(Flaky.class);
}
/**
* Returns true if {@link io.qameta.allure.Muted} annotation is present.
*
* @param annotatedElement the element to search annotations on.
* @return true if {@link io.qameta.allure.Muted} annotation is present, false otherwise.
*/
public static boolean isMuted(final AnnotatedElement annotatedElement) {
return annotatedElement.isAnnotationPresent(Muted.class);
}
/**
* Returns links created from Allure meta annotations specified on annotated element.
*
* @param annotatedElement the element to search annotations on.
* @return discovered links.
*/
public static Set getLinks(final AnnotatedElement annotatedElement) {
return getLinks(annotatedElement.getAnnotations());
}
/**
* Shortcut for {@link #getLinks(Collection)}.
*
* @param annotations annotations to analyse.
* @return discovered links.
*/
public static Set getLinks(final Annotation... annotations) {
return getLinks(asList(annotations));
}
/**
* Returns links from given annotations.
*
* @param annotations annotations to analyse.
* @return discovered links.
*/
public static Set getLinks(final Collection annotations) {
return extractMetaAnnotations(LinkAnnotation.class, AnnotationUtils::extractLinks, annotations)
.collect(Collectors.toSet());
}
/**
* Returns labels created from Allure meta annotations specified on annotated element.
* Shortcut for {@link #getLinks(Annotation...)}
*
* @param annotatedElement the element to search annotations on.
* @return discovered labels.
*/
public static Set