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

com.tngtech.archunit.lang.syntax.CodeUnitsThatInternal Maven / Gradle / Ivy

Go to download

A Java architecture test library, to specify and assert architecture rules in plain Java - Module 'archunit'

There is a newer version: 1.3.0
Show newest version
/*
 * Copyright 2014-2023 TNG Technology Consulting GmbH
 *
 * 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.tngtech.archunit.lang.syntax;

import java.util.List;

import com.tngtech.archunit.base.DescribedPredicate;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaCodeUnit;
import com.tngtech.archunit.core.domain.properties.HasThrowsClause;
import com.tngtech.archunit.lang.syntax.elements.CodeUnitsThat;

import static com.tngtech.archunit.base.DescribedPredicate.doNot;
import static com.tngtech.archunit.core.domain.properties.HasParameterTypes.Predicates.rawParameterTypes;
import static com.tngtech.archunit.core.domain.properties.HasReturnType.Predicates.rawReturnType;
import static com.tngtech.archunit.core.domain.properties.HasThrowsClause.Predicates.throwsClauseContainingType;
import static com.tngtech.archunit.lang.conditions.ArchPredicates.have;

class CodeUnitsThatInternal<
        CODE_UNIT extends JavaCodeUnit,
        CONJUNCTION extends AbstractGivenCodeUnitsInternal
        >
        extends MembersThatInternal
        implements CodeUnitsThat {

    CodeUnitsThatInternal(CONJUNCTION givenCodeUnits, PredicateAggregator currentPredicate) {
        super(givenCodeUnits, currentPredicate);
    }

    @Override
    public CONJUNCTION haveRawParameterTypes(Class... parameterTypes) {
        return withPredicate(have(rawParameterTypes(parameterTypes)));
    }

    @Override
    public CONJUNCTION doNotHaveRawParameterTypes(Class... parameterTypes) {
        return withPredicate(doNot(have(rawParameterTypes(parameterTypes))));
    }

    @Override
    public CONJUNCTION haveRawParameterTypes(String... parameterTypeNames) {
        return withPredicate(have(rawParameterTypes(parameterTypeNames)));
    }

    @Override
    public CONJUNCTION doNotHaveRawParameterTypes(String... parameterTypeNames) {
        return withPredicate(doNot(have(rawParameterTypes(parameterTypeNames))));
    }

    @Override
    public CONJUNCTION haveRawParameterTypes(DescribedPredicate> predicate) {
        return withPredicate(have(rawParameterTypes(predicate)));
    }

    @Override
    public CONJUNCTION doNotHaveRawParameterTypes(DescribedPredicate> predicate) {
        return withPredicate(doNot(have(rawParameterTypes(predicate))));
    }

    @Override
    public CONJUNCTION haveRawReturnType(Class type) {
        return withPredicate(have(rawReturnType(type)));
    }

    @Override
    public CONJUNCTION doNotHaveRawReturnType(Class type) {
        return withPredicate(doNot(have(rawReturnType(type))));
    }

    @Override
    public CONJUNCTION haveRawReturnType(String typeName) {
        return withPredicate(have(rawReturnType(typeName)));
    }

    @Override
    public CONJUNCTION doNotHaveRawReturnType(String typeName) {
        return withPredicate(doNot(have(rawReturnType(typeName))));
    }

    @Override
    public CONJUNCTION haveRawReturnType(DescribedPredicate predicate) {
        return withPredicate(have(rawReturnType(predicate)));
    }

    @Override
    public CONJUNCTION doNotHaveRawReturnType(DescribedPredicate predicate) {
        return withPredicate(doNot(have(rawReturnType(predicate))));
    }

    @Override
    public CONJUNCTION declareThrowableOfType(Class type) {
        return withPredicate(declareThrowableOfTypePredicate(type));
    }

    private DescribedPredicate> declareThrowableOfTypePredicate(Class type) {
        return throwsClauseContainingType(type).as("declare throwable of type " + type.getName());
    }

    @Override
    public CONJUNCTION doNotDeclareThrowableOfType(Class type) {
        return withPredicate(doNot(declareThrowableOfTypePredicate(type)));
    }

    @Override
    public CONJUNCTION declareThrowableOfType(String typeName) {
        return withPredicate(declareThrowableOfTypePredicate(typeName));
    }

    private DescribedPredicate> declareThrowableOfTypePredicate(String typeName) {
        return throwsClauseContainingType(typeName).as("declare throwable of type " + typeName);
    }

    @Override
    public CONJUNCTION doNotDeclareThrowableOfType(String typeName) {
        return withPredicate(doNot(declareThrowableOfTypePredicate(typeName)));
    }

    @Override
    public CONJUNCTION declareThrowableOfType(DescribedPredicate predicate) {
        return withPredicate(declareThrowableOfTypePredicate(predicate));
    }

    private DescribedPredicate> declareThrowableOfTypePredicate(DescribedPredicate predicate) {
        return throwsClauseContainingType(predicate).as("declare throwable of type " + predicate.getDescription());
    }

    @Override
    public CONJUNCTION doNotDeclareThrowableOfType(DescribedPredicate predicate) {
        return withPredicate(doNot(declareThrowableOfTypePredicate(predicate)));
    }

    private CONJUNCTION withPredicate(DescribedPredicate predicate) {
        return givenMembers.with(currentPredicate.add(predicate));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy