|
Groovy example source code file (StaticImportTest.groovy)
The Groovy StaticImportTest.groovy source code/* * Copyright 2003-2010 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 groovy import gls.CompilableTestSupport import static java.lang.Boolean.FALSE as F import static java.text.DateFormat.MEDIUM as M import static java.util.regex.Pattern.* import static java.text.DateFormat.MEDIUM import static junit.framework.Assert.format import static junit.framework.Assert.assertEquals import static groovy.StaticImportTarget.x import static groovy.StaticImportTarget.z // do not remove import static groovy.StaticImportTarget.cl import static java.lang.Math.* import static java.util.Calendar.getInstance as now import static groovy.API.* import static groovy.StaticImportChild.* import static groovy.bugs.Groovy4145.foo4145 import static groovy.Outer1.* import static groovy.Outer2.Inner2 import static groovy.Outer2.Inner2 as InnerAlias2 import static java.util.jar.Attributes.* import static java.util.jar.Attributes.Name as AttrName // TODO GROOVY-4287: reinstate next two imports //import static Outer3.* //import static Outer4.Inner4 class StaticImportTest extends CompilableTestSupport { void testFieldWithAliasInExpression() { assert !F } void testMethodAndField() { assert cos(2 * PI) == 1.0 } static myStaticMethod() { cos(2 * PI) } void testMethodAndFieldInStaticContext() { assert myStaticMethod() == 1.0 } void testMethodAndFieldInClosure() { def closure = { cos(2 * PI) } assert closure() == 1.0 } void testFieldAsObjectExpression() { assert PI.equals(Math.PI) } void testFieldAsArgumentList() { assert ("" + PI.toString()).contains('3.14') } void testFieldAliasing() { assert MEDIUM == M } void testMethodAliasing() { // GROOVY-1809 making this not possible on one line? def now = now().time assert now.class == Date } void testWildCardAliasing() { assert MULTILINE == java.util.regex.Pattern.MULTILINE } private format(a, b, c, ignored) { format(a, b, c) } void testMethodDefCanUseStaticallyImportedMethodWithSameNameButDiffArgs() { assert format("different", "abc", "aBc", 3) == 'different expected:<abc> but was: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.