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

org.gradle.model.internal.core.ModelTypeJavaTest Maven / Gradle / Ivy

There is a newer version: 8.6
Show newest version
/*
 * Copyright 2013 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.model.internal.core;

import org.gradle.model.internal.type.ModelType;
import org.junit.Test;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;

/**
 * Tests that need full static typing.
 */
public class ModelTypeJavaTest {
    static class Nested {
        class Child { }
    }

     void m1(T t, S s, R r) { }
     void m1(S s) { }
    void m2(List... lists) { }
    void m4(List... lists) { }
    void m5(Collection... collections) { }

    @Test
    public void testNestedParameterizedType() {
// Suppress - checkstyle gets confused with type params on the outer type
//CHECKSTYLE:OFF
        ModelType type = new ModelType.Child>() {};
        assertEquals(type.getDisplayName(), "ModelTypeJavaTest.Nested.Child");
        assertEquals(type.toString(), "org.gradle.model.internal.core.ModelTypeJavaTest.Nested.Child");

        ModelType listType = new ModelType.Child>>() {};

        assertEquals(listType.getDisplayName(), "List.Child>");
        assertEquals(listType.toString(), "java.util.List.Child>");
//CHECKSTYLE:ON
    }

    @Test
    public void testBuildType() throws Exception {
        assertEquals(new ModelType>() {}, buildMap(ModelType.of(String.class), ModelType.of(Integer.class)));
        assertEquals(new ModelType>() {}.hashCode(), buildMap(ModelType.of(String.class), ModelType.of(Integer.class)).hashCode());
    }

    static  ModelType> buildMap(ModelType k, ModelType v) {
        return new ModelType.Builder>() {}
                .where(new ModelType.Parameter() {}, k)
                .where(new ModelType.Parameter() {}, v)
                .build();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy