Skip to content

Commit 9452b90

Browse files
committed
Merge tests
1 parent 0da8faf commit 9452b90

File tree

70 files changed

+10298
-12198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+10298
-12198
lines changed

src/test/groovy/groovy/lang/GroovySystemTest.groovy

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,105 @@
1818
*/
1919
package groovy.lang
2020

21-
import groovy.test.GroovyTestCase
21+
22+
import org.junit.jupiter.api.Test
2223

2324
/**
2425
* Tests for the GroovySystem class
2526
*/
26-
class GroovySystemTest extends GroovyTestCase {
27-
27+
class GroovySystemTest {
28+
@Test
2829
void testGetMetaClassRegistry() {
29-
assert GroovySystem.metaClassRegistry
30-
assert GroovySystem.getMetaClassRegistry()
30+
def registry = GroovySystem.getMetaClassRegistry()
31+
assert registry != null
3132
}
3233

34+
@Test
3335
void testGroovyVersion() {
3436
assert GroovySystem.getVersion()
3537
}
38+
39+
// --- Merged from GroovySystemJUnit5Test ---
40+
@Test
41+
void testGetMetaClassRegistryReturnsSameInstance() {
42+
def registry1 = GroovySystem.getMetaClassRegistry()
43+
def registry2 = GroovySystem.getMetaClassRegistry()
44+
assert registry1.is(registry2)
45+
}
46+
47+
@Test
48+
void testGetVersion() {
49+
def version = GroovySystem.getVersion()
50+
assert version != null
51+
assert !version.isEmpty()
52+
}
53+
54+
@Test
55+
void testGetShortVersion() {
56+
def shortVersion = GroovySystem.getShortVersion()
57+
assert shortVersion != null
58+
59+
// Short version should contain exactly one dot
60+
def dotCount = shortVersion.length() - shortVersion.replace(".", "").length()
61+
assert 1 == dotCount
62+
63+
// Should start with a number
64+
assert Character.isDigit(shortVersion.charAt(0))
65+
}
66+
67+
@Test
68+
void testShortVersionIsPartOfFullVersion() {
69+
def fullVersion = GroovySystem.getVersion()
70+
def shortVersion = GroovySystem.getShortVersion()
71+
72+
assert fullVersion.startsWith(shortVersion)
73+
}
74+
75+
@Test
76+
void testIsKeepJavaMetaClassesDefault() {
77+
def original = GroovySystem.isKeepJavaMetaClasses()
78+
try {
79+
assert !original
80+
} finally {
81+
GroovySystem.setKeepJavaMetaClasses(original)
82+
}
83+
}
84+
85+
@Test
86+
void testSetKeepJavaMetaClasses() {
87+
def original = GroovySystem.isKeepJavaMetaClasses()
88+
try {
89+
GroovySystem.setKeepJavaMetaClasses(true)
90+
assert GroovySystem.isKeepJavaMetaClasses()
91+
92+
GroovySystem.setKeepJavaMetaClasses(false)
93+
assert !GroovySystem.isKeepJavaMetaClasses()
94+
} finally {
95+
GroovySystem.setKeepJavaMetaClasses(original)
96+
}
97+
}
98+
99+
@Test
100+
@SuppressWarnings("deprecation")
101+
void testIsUseReflection() {
102+
assert GroovySystem.isUseReflection()
103+
}
104+
105+
@Test
106+
@SuppressWarnings("deprecation")
107+
void testRunnerRegistry() {
108+
assert GroovySystem.RUNNER_REGISTRY != null
109+
}
110+
111+
@Test
112+
void testVersionFormat() {
113+
def version = GroovySystem.getVersion()
114+
assert version.matches("\\d+\\.\\d+\\.\\d+.*") : "Version should match pattern X.Y.Z[suffix], got: " + version
115+
}
116+
117+
@Test
118+
void testStopThreadedReferenceManager() {
119+
// This should not throw any exception
120+
GroovySystem.stopThreadedReferenceManager()
121+
}
36122
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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 groovy.lang
20+
21+
import org.junit.jupiter.api.Test
22+
23+
import static org.junit.jupiter.api.Assertions.*
24+
25+
/**
26+
* JUnit 5 tests for Reference class.
27+
*/
28+
class ReferenceTest {
29+
30+
@Test
31+
void testDefaultConstructor() {
32+
def ref = new Reference<String>()
33+
assertNull(ref.get())
34+
}
35+
36+
@Test
37+
void testConstructorWithValue() {
38+
def ref = new Reference<String>("hello")
39+
assertEquals("hello", ref.get())
40+
}
41+
42+
@Test
43+
void testGetAndSet() {
44+
def ref = new Reference<Integer>()
45+
assertNull(ref.get())
46+
47+
ref.set(42)
48+
assertEquals(42, ref.get())
49+
50+
ref.set(100)
51+
assertEquals(100, ref.get())
52+
}
53+
54+
@Test
55+
void testSetNull() {
56+
def ref = new Reference<String>("initial")
57+
assertEquals("initial", ref.get())
58+
59+
ref.set(null)
60+
assertNull(ref.get())
61+
}
62+
63+
@Test
64+
void testWithDifferentTypes() {
65+
def doubleRef = new Reference<Double>(3.14)
66+
assertEquals(3.14, doubleRef.get())
67+
68+
def boolRef = new Reference<Boolean>(true)
69+
assertTrue(boolRef.get())
70+
71+
def objRef = new Reference<Object>([1, 2, 3] as int[])
72+
assertArrayEquals([1, 2, 3] as int[], (int[]) objRef.get())
73+
}
74+
75+
@Test
76+
void testGetPropertyOnNullValue() {
77+
def ref = new Reference<String>()
78+
// When value is null, getProperty should delegate to super
79+
assertThrows(MissingPropertyException, { ->
80+
ref.getProperty("length")
81+
})
82+
}
83+
84+
@Test
85+
void testSetPropertyOnNullValue() {
86+
def ref = new Reference<Object>()
87+
// When value is null, setProperty should delegate to super
88+
assertThrows(MissingPropertyException, { ->
89+
ref.setProperty("someProp", "value")
90+
})
91+
}
92+
93+
@Test
94+
void testInvokeMethodOnNullValue() {
95+
def ref = new Reference<String>()
96+
// When value is null, invokeMethod delegates to super (GroovyObjectSupport)
97+
// It throws MissingMethodException for undefined methods
98+
assertThrows(MissingMethodException, { ->
99+
ref.invokeMethod("someUndefinedMethod", null)
100+
})
101+
}
102+
103+
@Test
104+
void testReferenceIsSerializable() {
105+
def ref = new Reference<String>("test")
106+
assertTrue(ref instanceof java.io.Serializable)
107+
}
108+
109+
@Test
110+
void testReferenceExtendsGroovyObjectSupport() {
111+
def ref = new Reference<String>()
112+
assertTrue(ref instanceof GroovyObjectSupport)
113+
}
114+
115+
@Test
116+
void testMultipleReferences() {
117+
def ref1 = new Reference<String>("one")
118+
def ref2 = new Reference<String>("two")
119+
120+
assertNotEquals(ref1.get(), ref2.get())
121+
122+
ref1.set("same")
123+
ref2.set("same")
124+
assertEquals(ref1.get(), ref2.get())
125+
}
126+
127+
@Test
128+
void testReferenceWithComplexObject() {
129+
def person = new PersonForTest("John", 30)
130+
def ref = new Reference<PersonForTest>(person)
131+
132+
assertSame(person, ref.get())
133+
assertEquals("John", ref.get().name)
134+
assertEquals(30, ref.get().age)
135+
}
136+
137+
@Test
138+
void testReferenceValueMutation() {
139+
def sb = new StringBuilder("initial")
140+
def ref = new Reference<StringBuilder>(sb)
141+
142+
sb.append(" modified")
143+
144+
// Since Reference holds the same object, mutation is visible
145+
assertEquals("initial modified", ref.get().toString())
146+
}
147+
148+
// Helper class moved to class level for Groovy compatibility
149+
static class PersonForTest {
150+
String name
151+
int age
152+
PersonForTest(String name, int age) {
153+
this.name = name
154+
this.age = age
155+
}
156+
}
157+
}

0 commit comments

Comments
 (0)