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

io.github.bekoenig.assertj.schemacrawler.api.AbstractNamedObjectWithAttributesAssert Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
package io.github.bekoenig.assertj.schemacrawler.api;

import org.assertj.core.api.InstanceOfAssertFactories;
import org.assertj.core.api.OptionalAssert;
import schemacrawler.schema.AttributedObject;
import schemacrawler.schema.DescribedObject;
import schemacrawler.schema.NamedObject;

import java.util.function.Predicate;

public abstract class AbstractNamedObjectWithAttributesAssert<
        SELF extends AbstractNamedObjectWithAttributesAssert,
        ACTUAL extends NamedObject & AttributedObject & DescribedObject>
        extends AbstractNamedObjectAssert {

    protected AbstractNamedObjectWithAttributesAssert(ACTUAL actual, Class selfType) {
        super(actual, selfType);
    }

    public  SELF matchesAttribute(String name, Class type, Predicate predicate) {
        extracting(x -> x.getAttribute(name))
                .asInstanceOf(InstanceOfAssertFactories.type(type))
                .matches(predicate);
        return myself;
    }

    public SELF matchesRemarks(Predicate predicate) {
        extracting(DescribedObject::getRemarks).matches(predicate);
        return myself;
    }

    public SELF hasAttribute(String name) {
        return returns(true, x -> x.getAttribute(name));
    }

    public SELF hasNoAttribute(String name) {
        return returns(false, x -> x.getAttribute(name));
    }

    public  OptionalAssert attribute(String name, Class resultType) {
        return extracting(x -> x.lookupAttribute(name))
                .asInstanceOf(InstanceOfAssertFactories.optional(resultType));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy