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

com.fitbur.testify.TestNeedDescriptor Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2015 Sharmarke Aden.
 *
 * 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 com.fitbur.testify;

import com.fitbur.testify.need.NeedDescriptor;
import java.lang.annotation.Annotation;
import java.util.Optional;
import static java.util.Optional.ofNullable;
import java.util.Set;
import static java.util.stream.Collectors.toSet;
import static java.util.stream.Stream.of;

/**
 * Spring need descriptor.
 *
 * @author saden
 */
public class TestNeedDescriptor implements NeedDescriptor {

    private final TestContext testContext;
    private final String methodName;

    public TestNeedDescriptor(
            TestContext testContext,
            String methodName) {
        this.testContext = testContext;
        this.methodName = methodName;
    }

    @Override
    public Object getTestInstance() {
        return testContext.getTestInstance();
    }

    @Override
    public Class getTestClass() {
        return testContext.getTestClass();
    }

    @Override
    public String getTestClassName() {
        return testContext.getTestClassName();
    }

    @Override
    public String getTestMethodName() {
        return methodName;
    }

    @Override
    public  Optional getAnnotation(Class type) {
        T result = testContext.getTestInstance().getClass().getAnnotation(type);

        return ofNullable(result);
    }

    @Override
    public  Set getAnnotations(Class type) {
        T[] result = testContext.getTestInstance().getClass().getAnnotationsByType(type);

        return of(result).collect(toSet());
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy