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

org.gradle.api.internal.CustomNamedDomainObjectCollectionTest.groovy Maven / Gradle / Ivy

There is a newer version: 8.11.1
Show newest version
/*
 * Copyright 2023 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 org.gradle.api.internal

import org.gradle.api.Action
import org.gradle.api.DomainObjectCollection
import org.gradle.api.NamedDomainObjectCollection
import org.gradle.api.NamedDomainObjectCollectionSchema
import org.gradle.api.NamedDomainObjectProvider
import org.gradle.api.Namer
import org.gradle.api.Rule
import org.gradle.api.UnknownDomainObjectException
import org.gradle.api.provider.Provider
import org.gradle.api.specs.Spec
import org.gradle.util.TestUtil
import spock.lang.Specification

import javax.annotation.Nullable

class CustomNamedDomainObjectCollectionTest extends Specification {

    def "custom collection not implementing named method triggers useful error message"() {
        when:
        TestUtil.objectFactory().newInstance(MyNamedDomainObjectCollection).named { !it.isEmpty() }

        then:
        UnsupportedOperationException e = thrown()
        e.getMessage() == "Method not implemented by org.gradle.api.internal.MyNamedDomainObjectCollection"
    }

}

class MyNamedDomainObjectCollection implements NamedDomainObjectCollection {
    @Override
    void addLater(Provider provider) {

    }

    @Override
    void addAllLater(Provider> provider) {

    }

    @Override
     DomainObjectCollection withType(Class type, Action configureAction) {
        return null
    }

    @Override
     DomainObjectCollection withType(Class type, Closure configureClosure) {
        return null
    }

    @Override
    Action whenObjectAdded(Action action) {
        return null
    }

    @Override
    void whenObjectAdded(Closure action) {

    }

    @Override
    Action whenObjectRemoved(Action action) {
        return null
    }

    @Override
    void whenObjectRemoved(Closure action) {

    }

    @Override
    void all(Action action) {

    }

    @Override
    void all(Closure action) {

    }

    @Override
    void configureEach(Action action) {

    }

    @Override
    Collection findAll(Closure spec) {
        return null
    }

    @Override
    boolean add(T e) {
        return false
    }

    @Override
    boolean addAll(Collection c) {
        return false
    }

    @Override
    Namer getNamer() {
        return null
    }

    @Override
    SortedMap getAsMap() {
        return null
    }

    @Override
    SortedSet getNames() {
        return null
    }

    @Nullable
    @Override
    T findByName(String name) {
        return null
    }

    @Override
    T getByName(String name) throws UnknownDomainObjectException {
        return null
    }

    @Override
    T getByName(String name, Closure configureClosure) throws UnknownDomainObjectException {
        return null
    }

    @Override
    T getByName(String name, Action configureAction) throws UnknownDomainObjectException {
        return null
    }

    @Override
    T getAt(String name) throws UnknownDomainObjectException {
        return null
    }

    @Override
    Rule addRule(Rule rule) {
        return null
    }

    @Override
    Rule addRule(String description, Closure ruleAction) {
        return null
    }

    @Override
    Rule addRule(String description, Action ruleAction) {
        return null
    }

    @Override
    List getRules() {
        return null
    }

    @Override
     NamedDomainObjectCollection withType(Class type) {
        return null
    }

    @Override
    NamedDomainObjectCollection matching(Spec spec) {
        return null
    }

    @Override
    NamedDomainObjectCollection matching(Closure spec) {
        return null
    }

    @Override
    NamedDomainObjectProvider named(String name) throws UnknownDomainObjectException {
        return null
    }

    @Override
    NamedDomainObjectProvider named(String name, Action configurationAction) throws UnknownDomainObjectException {
        return null
    }

    @Override
     NamedDomainObjectProvider named(String name, Class type) throws UnknownDomainObjectException {
        return null
    }

    @Override
     NamedDomainObjectProvider named(String name, Class type, Action configurationAction) throws UnknownDomainObjectException {
        return null
    }

    @Override
    NamedDomainObjectCollectionSchema getCollectionSchema() {
        return null
    }

    @Override
    int size() {
        return 0
    }

    @Override
    boolean isEmpty() {
        return false
    }

    @Override
    boolean contains(Object o) {
        return false
    }

    @Override
    Iterator iterator() {
        return null
    }

    @Override
    Object[] toArray() {
        return new Object[0]
    }

    @Override
     T1[] toArray(T1[] a) {
        return null
    }

    @Override
    boolean remove(Object o) {
        return false
    }

    @Override
    boolean containsAll(Collection c) {
        return false
    }

    @Override
    boolean removeAll(Collection c) {
        return false
    }

    @Override
    boolean retainAll(Collection c) {
        return false
    }

    @Override
    void clear() {

    }
}