org.gradle.api.reflect.TypeOfSpec.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 5.6 API redistribution.
/*
* Copyright 2017 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.reflect
import spock.lang.Specification
import java.lang.reflect.Type
import static org.gradle.api.reflect.TypeOf.parameterizedTypeOf
import static org.gradle.api.reflect.TypeOf.typeOf
class TypeOfSpec extends Specification {
static class InnerClass {}
def "to string"() {
expect:
new TypeOf() {}.toString() == 'org.gradle.api.reflect.TypeOfSpec.InnerClass'
new TypeOf>() {}.toString() == 'java.util.List'
new TypeOf() {}.toString() == 'java.lang.String'
new TypeOf>() {}.toString() == 'java.util.List'
new TypeOf() {}.toString() == 'java.lang.Object'
}
def "simple generic name"() {
expect:
new TypeOf() {}.simpleName == 'String'
new TypeOf>() {}.simpleName == 'List'
new TypeOf() {}.simpleName == 'Object'
}
def "equality"() {
given:
def a = new TypeOf() {}
def b = new TypeOf() {}
def c = new TypeOf>() {}
expect:
a != b
b != c
c != a
and:
a == new TypeOf() {}
b == new TypeOf() {}
c == new TypeOf>() {}
}
def "hashCode semantics"() {
given:
def a = new TypeOf() {}.hashCode()
def b = new TypeOf() {}.hashCode()
def c = new TypeOf>() {}.hashCode()
expect:
a != b
b != c
c != a
and:
a == new TypeOf() {}.hashCode()
b == new TypeOf() {}.hashCode()
c == new TypeOf>() {}.hashCode()
}
def "factory methods"() {
expect:
typeOf(String) == new TypeOf() {}
typeOf((Type) String) == new TypeOf() {}
parameterizedTypeOf(new TypeOf>() {}, typeOf(String)) == new TypeOf>() {}
parameterizedTypeOf(new TypeOf