Skip to content

Commit 723371c

Browse files
committed
junit jupiter
1 parent bcf8fbc commit 723371c

38 files changed

Lines changed: 483 additions & 622 deletions

src/test/groovy/bugs/ByteIndexBug.groovy

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ import org.junit.jupiter.api.Test
2222

2323
final class ByteIndexBug {
2424

25-
// TODO: this tests a string with 128 nulls - is that what is intended?
25+
// TODO: This tests a string with 128 nulls - is that what is intended?
2626
@Test
2727
void testBug() {
28-
def sb = new StringBuffer("\"\"\"\n")
29-
for (j in 0..127){ // 126 is okay.
30-
sb.append('$').append("{x}")
28+
def sb = new StringBuilder('"""\n')
29+
for (j in 0..127) { // 126 is okay
30+
sb.append('${x}')
3131
}
32-
sb.append("\n\"\"\"\n")
33-
def b = new Binding(x:null)
34-
new GroovyShell(b).evaluate(sb.toString(),"foo")
32+
sb.append('\n"""\n')
33+
def b = new Binding(x: null)
34+
new GroovyShell(b).evaluate(sb.toString(), 'foo')
3535
}
3636
}

src/test/groovy/bugs/ClosureVariableBug.groovy

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,27 @@ final class ClosureVariableBug {
5353
}
5454

5555
protected Integer callClosure(collection) {
56-
Integer x
57-
/** @todo
5856
Integer x = 0
59-
*/
6057
collection.each { x = it }
6158
return x
6259
}
6360

6461
@Test
6562
void testLocalVariableWithPrimitiveType() {
66-
assertScript """
63+
assertScript '''
6764
int x
6865
1.times { x=2 }
6966
assert x==2
70-
"""
71-
assertScript """
67+
'''
68+
assertScript '''
7269
long x
7370
1.times { x=2 }
7471
assert x==2
75-
"""
76-
assertScript """
72+
'''
73+
assertScript '''
7774
double x
7875
1.times { x=2 }
7976
assert x==2
80-
"""
77+
'''
8178
}
8279
}

src/test/groovy/bugs/Groovy3156And2621Bug.groovy renamed to src/test/groovy/bugs/Groovy2621.groovy

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,30 @@ package bugs
2020

2121
import org.junit.jupiter.api.Test
2222

23+
final class Groovy2621 {
2324

24-
class Groovy3156And2621Bug {
2525
@Test
26-
void testMethodNameResolutionInANestedClosure() {
27-
assert m() == 'method'
28-
assert c1() == 'method'
26+
void testSimilarNamesForMethodAndLocalWithLocalAsMethodArgument() {
27+
def convention = 'value'
28+
1.times {
29+
this.convention(convention)
30+
}
2931
}
3032

33+
void convention(String arg) {
34+
}
35+
36+
//--------------------------------------------------------------------------
37+
38+
// GROOVY-3156
3139
@Test
32-
void testSimilarNamesForMethodAndLocalWithLocalAsMethodArgument() {
33-
failingExecute()
40+
void testMethodNameResolutionInNestedClosure() {
41+
assert m() == 'method'
42+
assert c1() == 'method'
3443
}
3544

3645
def m = { return 'method' }
46+
3747
def c1 = {
3848
def m = { return 'c1' }
3949
def c2 = {
@@ -43,18 +53,9 @@ class Groovy3156And2621Bug {
4353
* It should resolve to outermost class' m().
4454
*/
4555
assert m() == 'c1'
56+
4657
return this.m()
4758
}
4859
return c2()
4960
}
50-
51-
void convention(String arg) {
52-
}
53-
54-
void failingExecute() {
55-
def convention= 'value'
56-
1.times {
57-
this.convention(convention)
58-
}
59-
}
6061
}
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,22 @@ package bugs
2020

2121
import org.junit.jupiter.api.Test
2222

23-
/**
24-
*/
25-
class Groovy308_Bug {
23+
final class Groovy308 {
2624

2725
@Test
2826
void testBug() {
2927
def out = new StringWriter()
30-
out << "hello " << "world!"
28+
out << 'hello ' << 'world!'
3129

3230
def value = out.toString()
33-
assert value == "hello world!"
31+
assert value == 'hello world!'
3432

3533
out = new ByteArrayOutputStream()
36-
out << "hello " << "world!"
34+
out << 'hello ' << 'world!'
3735

3836
value = new String(out.toByteArray())
39-
assert value == "hello world!"
37+
assert value == 'hello world!'
4038

41-
System.out << "hello" << " world!"
39+
System.out << 'hello' << ' world!'
4240
}
4341
}
44-
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,58 @@ package bugs
2020

2121
import org.junit.jupiter.api.Test
2222

23+
final class Groovy3135 {
2324

24-
class Groovy3135Bug {
25-
static Byte b = Byte.parseByte("1")
26-
static Short s = Short.parseShort("2")
27-
static Integer i = Integer.parseInt("3")
28-
static Long l = Long.parseLong("4")
29-
static Float f = Float.parseFloat("5")
30-
static Double d = Double.parseDouble("6")
31-
static BigInteger bi = new BigInteger("7")
32-
static BigDecimal bd = new BigDecimal("8")
25+
private static Byte b = Byte.parseByte('1')
26+
private static Short s = Short.parseShort('2')
27+
private static Integer i = Integer.parseInt('3')
28+
private static Long l = Long.parseLong('4')
29+
private static Float f = Float.parseFloat('5')
30+
private static Double d = Double.parseDouble('6')
31+
private static BigInteger bi = new BigInteger('7')
32+
private static BigDecimal bd = new BigDecimal('8')
3333

34-
def values
34+
private Object values
3535

3636
@Test
3737
void testConversionForPrimitiveTypeVarArgs() {
38-
39-
setVarArgsShort("", b, s)
38+
setVarArgsShort('', b, s)
4039
checkConversionAndVarArgCount(Short.TYPE, 2)
4140

42-
setVarArgsInteger("", b, s, i)
41+
setVarArgsInteger('', b, s, i)
4342
checkConversionAndVarArgCount(Integer.TYPE, 3)
4443

45-
setVarArgsLong("", b, s, i, l)
44+
setVarArgsLong('', b, s, i, l)
4645
checkConversionAndVarArgCount(Long.TYPE, 4)
4746

48-
setVarArgsFloat("", b, s, i, l, f)
47+
setVarArgsFloat('', b, s, i, l, f)
4948
checkConversionAndVarArgCount(Float.TYPE, 5)
5049

51-
setVarArgsDouble("", b, s, i, l, f, d, bi, bd)
50+
setVarArgsDouble('', b, s, i, l, f, d, bi, bd)
5251
checkConversionAndVarArgCount(Double.TYPE, 8)
5352
}
5453

55-
def setVarArgsShort(String str, short... varArgValues) {
54+
void setVarArgsShort(String str, short... varArgValues) {
5655
values = varArgValues
5756
}
5857

59-
def setVarArgsInteger(String str, int... varArgValues) {
58+
void setVarArgsInteger(String str, int... varArgValues) {
6059
values = varArgValues
6160
}
6261

63-
def setVarArgsLong(String str, long... varArgValues) {
62+
void setVarArgsLong(String str, long... varArgValues) {
6463
values = varArgValues
6564
}
6665

67-
def setVarArgsFloat(String str, float... varArgValues) {
66+
void setVarArgsFloat(String str, float... varArgValues) {
6867
values = varArgValues
6968
}
7069

71-
def setVarArgsDouble(String str, double... varArgValues) {
70+
void setVarArgsDouble(String str, double... varArgValues) {
7271
values = varArgValues
7372
}
7473

75-
def checkConversionAndVarArgCount(expectedType, varArgsCount) {
74+
void checkConversionAndVarArgCount(expectedType, varArgsCount) {
7675
assert values.class.componentType == expectedType
7776
assert values.size() == varArgsCount
7877
}
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,41 @@ package bugs
2121
import groovy.mock.interceptor.StubFor
2222
import org.junit.jupiter.api.Test
2323

24-
class Groovy3139Bug {
24+
final class Groovy3139 {
2525

2626
@Test
2727
void testStubbingIssueDueToCachingWhenUsing2Stubs() {
2828
def urlStub1 = new StubFor(URL)
29-
urlStub1.demand.openConnection {""}
29+
urlStub1.demand.openConnection {''}
3030
urlStub1.use {
31-
def get = new Get2(url: "http://localhost")
31+
def get = new Get2(url: 'http://localhost')
3232
def result = get.text
3333
}
3434

3535
def urlStub2 = new StubFor(URL)
3636
// the following stubbed call is on urlStub2 and its demand cound should be separate.
3737
// Currently due to caching of MockProxyMetaClass, it gets counted towards urlStub1 demands
3838
// and throws "End of demands" exception
39-
urlStub2.demand.openConnection {""}
39+
urlStub2.demand.openConnection {''}
4040
urlStub2.use {
41-
def get = new Get2(url: "http://localhost")
41+
def get = new Get2(url: 'http://localhost')
4242
def result = get.text
4343
}
4444
}
45-
}
4645

47-
class Get2{
48-
String url
46+
static class Get2 {
47+
48+
String url
4949

50-
String getText() {
50+
String getText() {
5151
def aUrl = new URL(toString())
52-
def conn = aUrl.openConnection()
53-
return "DUMMY"
54-
}
52+
def conn = aUrl.openConnection()
53+
return 'DUMMY'
54+
}
5555

56-
String toString(){
57-
return url
56+
@Override
57+
String toString() {
58+
return url
59+
}
5860
}
5961
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package bugs
20+
21+
import org.junit.jupiter.api.Test
22+
23+
final class Groovy3163 {
24+
25+
@Test
26+
void testSuperOverStatic() {
27+
def siws = new Groovy3163SomeImplementorWithStatic()
28+
29+
assert siws.build(1)[0] == 1
30+
31+
def c = { -> 'foo ' }
32+
33+
//def s = c as Script
34+
//assert s.is(siws.build(s)[0])
35+
36+
assert c.is(siws.build(c)[0])
37+
}
38+
39+
static class Groovy3163SomeBaseClass {
40+
41+
Object build(Integer i) {
42+
return i
43+
}
44+
45+
Object build(BigInteger i) {
46+
return i
47+
}
48+
49+
Object build(Class c) {
50+
return c
51+
}
52+
53+
Object build(Script s) {
54+
return s
55+
}
56+
}
57+
58+
static class Groovy3163SomeImplementorWithStatic extends Groovy3163SomeBaseClass {
59+
60+
// Comment this out, otherwise the super.build(x) calls won't match the members in our parent.
61+
static Object build(Closure c) {
62+
[c]
63+
}
64+
65+
// This one will also block a super.build, but it's the Script one.
66+
static Object build(BigDecimal d) {
67+
[d]
68+
}
69+
70+
Object build(Integer i) {
71+
[super.build(i)]
72+
}
73+
74+
Object build(Script s) {
75+
[super.build(s)]
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)