From commits-return-9090-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Fri Aug 30 19:28:27 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id C9B2718065E for ; Fri, 30 Aug 2019 21:28:26 +0200 (CEST) Received: (qmail 11427 invoked by uid 500); 30 Aug 2019 19:28:26 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 11416 invoked by uid 99); 30 Aug 2019 19:28:26 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Aug 2019 19:28:26 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 1A4F08601F; Fri, 30 Aug 2019 19:28:26 +0000 (UTC) Date: Fri, 30 Aug 2019 19:28:26 +0000 To: "commits@groovy.apache.org" Subject: [groovy] branch master updated: JUnit 4 refactor MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <156719330595.30335.4625965924747535567@gitbox.apache.org> From: emilles@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: groovy X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: ff20e65c2e108fc3432fdb69e7f56ef26edfebcb X-Git-Newrev: 4c3da9c84ffeb17a62bce0f7c5302f04092f7fc4 X-Git-Rev: 4c3da9c84ffeb17a62bce0f7c5302f04092f7fc4 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. emilles pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/groovy.git The following commit(s) were added to refs/heads/master by this push: new 4c3da9c JUnit 4 refactor 4c3da9c is described below commit 4c3da9c84ffeb17a62bce0f7c5302f04092f7fc4 Author: Eric Milles AuthorDate: Fri Aug 30 14:19:47 2019 -0500 JUnit 4 refactor --- src/test/groovy/bugs/Groovy3311.groovy | 55 ++++++++++++++++++++++ src/test/groovy/bugs/Groovy3311Bug.groovy | 33 ------------- .../{Groovy8943Bug.groovy => Groovy8943.groovy} | 10 +++- .../{Groovy8947Bug.groovy => Groovy8947.groovy} | 39 ++++++++------- .../{Groovy9215Bug.groovy => Groovy9215.groovy} | 49 +++++++++++-------- .../{Groovy9217Bug.groovy => Groovy9217.groovy} | 21 ++++++--- .../{Groovy9226Bug.groovy => Groovy9226.groovy} | 17 +++++-- 7 files changed, 143 insertions(+), 81 deletions(-) diff --git a/src/test/groovy/bugs/Groovy3311.groovy b/src/test/groovy/bugs/Groovy3311.groovy new file mode 100644 index 0000000..b95c4c4 --- /dev/null +++ b/src/test/groovy/bugs/Groovy3311.groovy @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.bugs + +import groovy.transform.CompileStatic +import org.junit.Test + +import static groovy.test.GroovyAssert.assertScript + +@CompileStatic +final class Groovy3311 { + + @Test + void testStaticInitUsingOwnConstructor() { + assertScript ''' + class Day extends Date { + static Day get(_date) { + return new Day(new java.text.SimpleDateFormat('MM.dd.yyyy').parse(_date)) + } + Day(Date _date) { + super(_date.time) + def time = getTime() + 24.times { hour -> + hoursOfTheDay << new Date(time + hour*1000*60*60) + } + } + List hoursOfTheDay = [] + + @Override String toString() { + this.format('MM.dd.yyyy') + } + + static def period = (1..3).collect { get "12.3${it}.1999" } + } + + assert Day.period*.toString() == ['12.31.1999', '01.01.2000', '01.02.2000'] + ''' + } +} diff --git a/src/test/groovy/bugs/Groovy3311Bug.groovy b/src/test/groovy/bugs/Groovy3311Bug.groovy deleted file mode 100644 index 9b41244..0000000 --- a/src/test/groovy/bugs/Groovy3311Bug.groovy +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.bugs - -class Groovy3311Bug extends GroovyTestCase { - static period = new Groovy3311Bug() - static period2 = 24 - - def Groovy3311Bug() { - // the pre-defined constant for 24 should be correctly init before next statement - assert (24 != null) - } - - def void testStaticInitUsingOwnConstructorUsingAPredefinedConstant() { - assert (Groovy3311Bug.period2 == 24) - } -} diff --git a/src/test/groovy/bugs/Groovy8943Bug.groovy b/src/test/groovy/bugs/Groovy8943.groovy similarity index 88% rename from src/test/groovy/bugs/Groovy8943Bug.groovy rename to src/test/groovy/bugs/Groovy8943.groovy index 1721bba..69fd9d2 100644 --- a/src/test/groovy/bugs/Groovy8943Bug.groovy +++ b/src/test/groovy/bugs/Groovy8943.groovy @@ -18,7 +18,15 @@ */ package groovy.bugs -class Groovy8943Bug extends GroovyTestCase { +import groovy.transform.CompileStatic +import org.junit.Test + +import static groovy.test.GroovyAssert.assertScript + +@CompileStatic +final class Groovy8943 { + + @Test void testImplicitGetAtInStaticMethod() { assertScript ''' class Pippo { diff --git a/src/test/groovy/bugs/Groovy8947Bug.groovy b/src/test/groovy/bugs/Groovy8947.groovy similarity index 87% rename from src/test/groovy/bugs/Groovy8947Bug.groovy rename to src/test/groovy/bugs/Groovy8947.groovy index 5c858b3..d7f8c6c 100644 --- a/src/test/groovy/bugs/Groovy8947Bug.groovy +++ b/src/test/groovy/bugs/Groovy8947.groovy @@ -18,13 +18,21 @@ */ package groovy.bugs -class Groovy8947Bug extends GroovyTestCase { +import groovy.transform.CompileStatic +import org.junit.Test + +import static groovy.test.GroovyAssert.assertScript +import static groovy.test.GroovyAssert.shouldFail + +@CompileStatic +final class Groovy8947 { + + @Test void testResolvingNonStaticInnerClass() { assertScript ''' public class Computer { public class Cpu { int coreNumber - public Cpu(int coreNumber) { this.coreNumber = coreNumber } @@ -33,60 +41,57 @@ class Groovy8947Bug extends GroovyTestCase { return new Computer().new Cpu(coreNumber) } } - + assert 4 == new Computer().new Cpu(4).coreNumber - assert 4 == Computer.newCpuInstance(4).coreNumber assert 0 == new HashSet(new ArrayList()).size() ''' } + @Test void testResolvingNonStaticInnerClass2() { assertScript ''' public class Computer { public class Cpu { int coreNumber - public Cpu(int coreNumber) { this.coreNumber = coreNumber } } - static newComputerInstance() { return new Computer() } - static newCpuInstance(int coreNumber) { // `new Cpu(coreNumber)` is inside of the outer class `Computer`, so we can resolve `Cpu` return newComputerInstance().new Cpu(coreNumber) - } + } } - - assert 4 == Computer.newCpuInstance(4).coreNumber + + assert 4 == Computer.newCpuInstance(4).coreNumber ''' } + @Test void testResolvingNonStaticInnerClass3() { - def errMsg = shouldFail ''' + def err = shouldFail ''' public class Computer { public class Cpu { int coreNumber - + public Cpu(int coreNumber) { this.coreNumber = coreNumber } } } - def newComputerInstance() { return new Computer() } - - // `new Cpu(4)` is outside of outer class `Computer` and the return type of `newComputerInstance()` can not be resolved, + + // `new Cpu(4)` is outside of outer class `Computer` and the return type of `newComputerInstance()` can not be resolved, // so we does not support this syntax outside of outer class - assert 4 == newComputerInstance().new Cpu(4).coreNumber + assert 4 == newComputerInstance().new Cpu(4).coreNumber ''' - assert errMsg.contains('unable to resolve class Cpu') + assert err =~ 'unable to resolve class Cpu' } } diff --git a/src/test/groovy/bugs/Groovy9215Bug.groovy b/src/test/groovy/bugs/Groovy9215.groovy similarity index 93% rename from src/test/groovy/bugs/Groovy9215Bug.groovy rename to src/test/groovy/bugs/Groovy9215.groovy index d534515..ebbb695 100644 --- a/src/test/groovy/bugs/Groovy9215Bug.groovy +++ b/src/test/groovy/bugs/Groovy9215.groovy @@ -19,12 +19,20 @@ package groovy.bugs -class Groovy9215Bug extends GroovyTestCase { +import groovy.transform.CompileStatic +import org.junit.Test + +import static groovy.test.GroovyAssert.assertScript + +@CompileStatic +final class Groovy9215 { + + @Test void testDuplicatedAnnotations1() { assertScript ''' import groovy.transform.CompileStatic import groovy.transform.TypeChecked - + @TypeChecked @CompileStatic class Data { @@ -32,16 +40,16 @@ class Groovy9215Bug extends GroovyTestCase { c("hello") } } - + @CompileStatic @CompileStatic class Op { public Data d = new Data() - + void aFunc(Closure c){ c() } - + void broken() { aFunc({ d.getThing({ String res -> @@ -50,16 +58,17 @@ class Groovy9215Bug extends GroovyTestCase { }) } } - + assert Op.class ''' } + @Test void testDuplicatedAnnotations2() { assertScript ''' import groovy.transform.CompileStatic import groovy.transform.TypeChecked - + @TypeChecked @CompileStatic class Data { @@ -67,16 +76,16 @@ class Groovy9215Bug extends GroovyTestCase { c("hello") } } - + @TypeChecked @CompileStatic class Op { public Data d = new Data() - + void aFunc(Closure c){ c() } - + void broken() { aFunc({ d.getThing({ String res -> @@ -85,16 +94,17 @@ class Groovy9215Bug extends GroovyTestCase { }) } } - + assert Op.class ''' } + @Test void testDuplicatedAnnotations3() { assertScript ''' import groovy.transform.CompileStatic import groovy.transform.TypeChecked - + @TypeChecked @CompileStatic class Data { @@ -102,16 +112,16 @@ class Groovy9215Bug extends GroovyTestCase { c("hello") } } - + @TypeChecked @TypeChecked class Op { public Data d = new Data() - + void aFunc(Closure c){ c() } - + void broken() { aFunc({ d.getThing({ String res -> @@ -120,21 +130,22 @@ class Groovy9215Bug extends GroovyTestCase { }) } } - + assert Op.class ''' } + @Test void testDuplicatedAnnotations4() { assertScript ''' import groovy.transform.CompileDynamic import groovy.transform.CompileStatic import groovy.transform.TypeChecked - + class Person { String name } - + @CompileStatic // ignored @CompileDynamic // taken effect @TypeChecked // ignored @@ -143,7 +154,7 @@ class Groovy9215Bug extends GroovyTestCase { def person = new Person(name:"Daniel.Sun") assert "I'm Daniel.Sun" == person.introduce() } - + x() ''' } diff --git a/src/test/groovy/bugs/Groovy9217Bug.groovy b/src/test/groovy/bugs/Groovy9217.groovy similarity index 66% rename from src/test/groovy/bugs/Groovy9217Bug.groovy rename to src/test/groovy/bugs/Groovy9217.groovy index 3d11c93..d8ac56b 100644 --- a/src/test/groovy/bugs/Groovy9217Bug.groovy +++ b/src/test/groovy/bugs/Groovy9217.groovy @@ -18,12 +18,21 @@ */ package groovy.bugs -// TODO add JVM option `--illegal-access=deny` when all warnings fixed -class Groovy9217Bug extends GroovyTestCase { +import groovy.transform.CompileStatic +import org.junit.Test + +// TODO: add JVM option `--illegal-access=deny` when all warnings fixed +@CompileStatic +final class Groovy9217 { + + @Test void testSetProperty() { - HttpURLConnection conn = new URL('http://www.bing.com').openConnection() as HttpURLConnection - conn.requestMethod = 'HEAD' - assert 'HEAD' == conn.requestMethod - conn.disconnect() + def conn = new URL('http://www.bing.com').openConnection() as HttpURLConnection + try { + conn.requestMethod = 'HEAD' + assert 'HEAD' == conn.requestMethod + } finally { + conn.disconnect() + } } } diff --git a/src/test/groovy/bugs/Groovy9226Bug.groovy b/src/test/groovy/bugs/Groovy9226.groovy similarity index 89% rename from src/test/groovy/bugs/Groovy9226Bug.groovy rename to src/test/groovy/bugs/Groovy9226.groovy index 30fd05d..a2bb199 100644 --- a/src/test/groovy/bugs/Groovy9226Bug.groovy +++ b/src/test/groovy/bugs/Groovy9226.groovy @@ -19,25 +19,32 @@ package groovy.bugs -class Groovy9226Bug extends GroovyTestCase { +import groovy.transform.CompileStatic +import org.junit.Test + +import static groovy.test.GroovyAssert.assertScript + +@CompileStatic +final class Groovy9226 { + + @Test void testDuplicatedAnnotations5() { assertScript ''' import groovy.transform.CompileStatic import groovy.transform.TypeChecked - + @CompileStatic class Super { String toString() { 'Super' } } - + @TypeChecked @CompileStatic class Child extends Super { String toString() { 'Child extends ' + super.toString() } } - + assert new Child().toString() ''' } - }