Skip to content

Commit e1ff27e

Browse files
committed
junit jupiter
1 parent 1872759 commit e1ff27e

22 files changed

Lines changed: 231 additions & 254 deletions
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,42 @@ package bugs
2121
import groovy.mock.interceptor.StubFor
2222
import org.junit.jupiter.api.Test
2323

24-
class Groovy3403Bug {
24+
final class Groovy3403 {
2525

2626
@Test
2727
void testStubIssueForStaticMethodsDueToCallSiteCachingWhenUsing2Stubs() {
2828
def stub1 = new StubFor(Main3403)
2929
stub1.demand.test() {
30-
return "stubbed call made - 1"
30+
return 'stubbed call made - 1'
3131
}
3232

3333
def ot = new Helper3403()
3434

3535
stub1.use {
36-
assert ot.doTest() == "stubbed call made - 1"
36+
assert ot.doTest() == 'stubbed call made - 1'
3737
}
3838

3939
def stub2 = new StubFor(Main3403)
4040
stub2.demand.test() {
41-
return "stubbed call made - 2"
41+
return 'stubbed call made - 2'
4242
}
4343

4444
// the following stubbed call is on stub2 and its demand count should be separate.
4545
// Currently due to caching of MockProxyMetaClass, it gets counted towards stub1 demands
4646
// and throws "End of demands" exception
4747
stub2.use {
48-
assert ot.doTest() == "stubbed call made - 2"
48+
assert ot.doTest() == 'stubbed call made - 2'
4949
}
5050
}
51-
}
5251

53-
class Main3403 {
54-
static test(){
55-
}
56-
}
52+
static class Main3403 {
53+
static test() {
54+
}
55+
}
5756

58-
class Helper3403 {
59-
def doTest() {
60-
Main3403.test()
57+
static class Helper3403 {
58+
def doTest() {
59+
Main3403.test()
60+
}
6161
}
6262
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ package bugs
2121
import org.junit.jupiter.api.AfterEach
2222
import org.junit.jupiter.api.Test
2323

24-
class Groovy3405Bug {
24+
final class Groovy3405 {
2525

2626
@AfterEach
2727
void tearDown() {
@@ -31,14 +31,14 @@ class Groovy3405Bug {
3131
@Test
3232
void testAddingStaticMethodsOnMCWithDefaultParameters() {
3333
// test with 2 params having default values
34-
String.metaClass.'static'.testStaticTwoParams = { first = "foo", second = "bar" -> return "$first - $second" }
35-
assert "baz - qux" == "".testStaticTwoParams("baz", "qux")
36-
assert "baz - bar" == "".testStaticTwoParams("baz")
37-
assert "foo - bar" == "".testStaticTwoParams()
34+
String.metaClass.'static'.testStaticTwoParams = { first = 'foo', second = 'bar' -> return "$first - $second" }
35+
assert 'baz - qux' == ''.testStaticTwoParams('baz', 'qux')
36+
assert 'baz - bar' == ''.testStaticTwoParams('baz')
37+
assert 'foo - bar' == ''.testStaticTwoParams()
3838

3939
// test with 1 param having default value
40-
String.metaClass.'static'.testStaticOneParam = { first = "foo" -> return first }
41-
assert "baz" == "".testStaticOneParam("baz")
42-
assert "foo" == "".testStaticOneParam()
40+
String.metaClass.'static'.testStaticOneParam = { first = 'foo' -> return first }
41+
assert 'baz' == ''.testStaticOneParam('baz')
42+
assert 'foo' == ''.testStaticOneParam()
4343
}
4444
}
Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,56 +22,71 @@ import org.junit.jupiter.api.Test
2222

2323
import static groovy.test.GroovyAssert.assertScript
2424

25-
26-
class Groovy3410Bug {
25+
final class Groovy3410 {
2726

2827
@Test
29-
void testClassVerificationErrorsWithBooleanExpUsingPrimitiveFields() {
30-
assertScript """
28+
void testClassVerificationErrorsWithBooleanExpUsingPrimitiveFields1() {
29+
assertScript '''
3130
class Groovy3405N1 {
3231
long id // or float or double
3332
3433
boolean bar() {
3534
return (id ? true : false)
3635
}
3736
}
37+
3838
println new Groovy3405N1()
39-
"""
39+
'''
40+
}
4041

41-
assertScript """
42+
@Test
43+
void testClassVerificationErrorsWithBooleanExpUsingPrimitiveFields2() {
44+
assertScript '''
4245
class Groovy3405N2 {
4346
long id
4447
def bar() {
45-
return (id ? "a" : "b")
48+
return (id ? 'a' : 'b')
4649
}
4750
}
51+
4852
println new Groovy3405N2()
49-
"""
53+
'''
54+
}
5055

51-
assertScript """
56+
@Test
57+
void testClassVerificationErrorsWithBooleanExpUsingPrimitiveFields3() {
58+
assertScript '''
5259
class Groovy3405N3 {
5360
long id = 0
5461
def bar() {
55-
assert id, "Done"
62+
assert id, 'Done'
5663
}
5764
}
65+
5866
println new Groovy3405N3()
59-
"""
67+
'''
68+
}
6069

61-
assertScript """
70+
@Test
71+
void testClassVerificationErrorsWithBooleanExpUsingPrimitiveFields4() {
72+
assertScript '''
6273
class Groovy3405N4 {
6374
long id = 0
6475
def bar() {
6576
while(id){
66-
print "here"
77+
print 'here'
6778
break
6879
}
6980
}
7081
}
82+
7183
println new Groovy3405N4()
72-
"""
84+
'''
85+
}
7386

74-
assertScript """
87+
@Test
88+
void testClassVerificationErrorsWithBooleanExpUsingPrimitiveFields5() {
89+
assertScript '''
7590
class Groovy3405N5 {
7691
long id = 0
7792
def bar() {
@@ -82,7 +97,8 @@ class Groovy3410Bug {
8297
}
8398
}
8499
}
100+
85101
println new Groovy3405N5()
86-
"""
102+
'''
87103
}
88104
}

src/test/groovy/bugs/Groovy3422.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test
2323
import static groovy.test.GroovyAssert.assertScript
2424

2525
final class Groovy3422 {
26+
2627
@Test
2728
void testStaticClosureProperty() {
2829
assertScript '''
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import org.junit.jupiter.api.AfterEach
2222
import org.junit.jupiter.api.BeforeEach
2323
import org.junit.jupiter.api.Test
2424

25-
class Groovy3424Bug {
25+
final class Groovy3424 {
2626

27-
MetaClassRegistry registry
28-
MetaClass originalMetaClass
27+
private MetaClassRegistry registry
28+
private MetaClass originalMetaClass
2929

3030
@BeforeEach
3131
void setUp() {
@@ -84,15 +84,15 @@ class Groovy3424Bug {
8484
assert newFoo() instanceof Groovy3424Foo
8585
}
8686

87-
}
88-
89-
class Groovy3424Foo {}
90-
91-
class Groovy3424ClassProxyMetaClass extends ProxyMetaClass {
92-
Groovy3424ClassProxyMetaClass(MetaClassRegistry metaClassRegistry, Class aClass, MetaClass adaptee) {
93-
super(metaClassRegistry, aClass, adaptee)
87+
static class Groovy3424Foo {
9488
}
95-
public Object invokeConstructor(final Object[] arguments) {
96-
'constructor'
89+
90+
static class Groovy3424ClassProxyMetaClass extends ProxyMetaClass {
91+
Groovy3424ClassProxyMetaClass(MetaClassRegistry metaClassRegistry, Class aClass, MetaClass adaptee) {
92+
super(metaClassRegistry, aClass, adaptee)
93+
}
94+
Object invokeConstructor(final Object[] arguments) {
95+
'constructor'
96+
}
9797
}
9898
}
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import org.junit.jupiter.api.AfterEach
2222
import org.junit.jupiter.api.BeforeEach
2323
import org.junit.jupiter.api.Test
2424

25-
class Groovy3426Bug {
25+
final class Groovy3426 {
2626

27-
MetaClassRegistry registry
28-
MetaClass originalMetaClass
27+
private MetaClassRegistry registry
28+
private MetaClass originalMetaClass
2929

3030
@BeforeEach
3131
void setUp() {
@@ -54,17 +54,16 @@ class Groovy3426Bug {
5454
assert 'foo' == getFoo()
5555
}
5656

57-
}
58-
59-
class Groovy3426Foo {
60-
static get() { 'foo' }
61-
}
62-
63-
class Groovy3426ClassProxyMetaClass extends ProxyMetaClass {
64-
Groovy3426ClassProxyMetaClass(MetaClassRegistry metaClassRegistry, Class aClass, MetaClass adaptee) {
65-
super(metaClassRegistry, aClass, adaptee)
57+
static class Groovy3426Foo {
58+
static get() { 'foo' }
6659
}
67-
public Object invokeStaticMethod(final Object aClass, final String method, final Object[] arguments) {
68-
'static'
60+
61+
static class Groovy3426ClassProxyMetaClass extends ProxyMetaClass {
62+
Groovy3426ClassProxyMetaClass(MetaClassRegistry metaClassRegistry, Class aClass, MetaClass adaptee) {
63+
super(metaClassRegistry, aClass, adaptee)
64+
}
65+
public Object invokeStaticMethod(final Object aClass, final String method, final Object[] arguments) {
66+
'static'
67+
}
6968
}
7069
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ package bugs
2020

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

23-
class Groovy3446Bug {
23+
final class Groovy3446 {
24+
2425
@Test
2526
void testLocalMethodFavoredOverStaticallyImportedMethod() {
26-
assert currentTimeMillis() == "local method called"
27+
assert currentTimeMillis() == 'local method called'
2728
}
2829

2930
def currentTimeMillis() {
30-
"local method called"
31+
'local method called'
3132
}
3233
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,20 @@ import org.junit.jupiter.api.Test
2222

2323
import static groovy.test.GroovyAssert.assertScript
2424

25-
26-
class Groovy3462Bug {
25+
final class Groovy3462 {
2726

2827
@Test
2928
void testClosureWithParameterHavingDefaultExpression() {
30-
assertScript """
31-
month = { String date = new Date().format("yyyyMM") ->
29+
assertScript '''
30+
month = { String date = new Date().format('yyyyMM') ->
3231
date
3332
}
3433
35-
def obj = month("200101")
36-
assert month("200101") == "200101"
34+
def obj = month('200101')
35+
assert month('200101') == '200101'
3736
38-
String expectedDate = new Date().format("yyyyMM")
37+
String expectedDate = new Date().format('yyyyMM')
3938
assert month() == expectedDate
40-
"""
39+
'''
4140
}
4241
}

0 commit comments

Comments
 (0)