Skip to content

Commit 0c82aee

Browse files
committed
GROOVY-7439: add test case
1 parent 6da2f7a commit 0c82aee

2 files changed

Lines changed: 48 additions & 25 deletions

File tree

src/test/groovy/groovy/util/logging/Slf4jTest.groovy

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ import ch.qos.logback.classic.LoggerContext
2424
import ch.qos.logback.classic.spi.LoggingEvent
2525
import ch.qos.logback.core.OutputStreamAppender
2626
import ch.qos.logback.core.layout.EchoLayout
27-
import org.junit.After
28-
import org.junit.Before
29-
import org.junit.Test
27+
import groovy.test.NotYetImplemented
28+
import org.junit.jupiter.api.AfterEach
29+
import org.junit.jupiter.api.BeforeEach
30+
import org.junit.jupiter.api.Test
31+
import org.junit.jupiter.params.ParameterizedTest
32+
import org.junit.jupiter.params.provider.ValueSource
3033
import org.slf4j.LoggerFactory
3134

3235
import java.lang.reflect.Modifier
@@ -60,7 +63,7 @@ final class Slf4jTest {
6063
private LogbackInterceptingAppender appender
6164
private Logger logger
6265

63-
@Before
66+
@BeforeEach
6467
void setUp() {
6568
appender = new LogbackInterceptingAppender()
6669
appender.outputStream = new ByteArrayOutputStream()
@@ -74,7 +77,7 @@ final class Slf4jTest {
7477
logger.level = Level.ALL
7578
}
7679

77-
@After
80+
@AfterEach
7881
void tearDown() {
7982
logger.detachAppender(appender)
8083
}
@@ -293,7 +296,8 @@ final class Slf4jTest {
293296
assert events[ind].message == 'trace called'
294297
}
295298

296-
@Test // GROOVY-6373
299+
// GROOVY-6373
300+
@Test
297301
void testLogWithInnerClasses() {
298302
Class clazz = new GroovyClassLoader().parseClass('''
299303
@groovy.util.logging.Slf4j('logger')
@@ -323,7 +327,8 @@ final class Slf4jTest {
323327
assert events[ind].message == 'inner called'
324328
}
325329

326-
@Test // GROOVY-6834
330+
// GROOVY-6834
331+
@Test
327332
void testLogTransformInteractionWithAnonInnerClass() {
328333
assertScript '''
329334
@groovy.util.logging.Slf4j
@@ -344,7 +349,8 @@ final class Slf4jTest {
344349
'''
345350
}
346351

347-
@Test // GROOVY-6873
352+
// GROOVY-6873
353+
@Test
348354
void testLogTransformInteractionWithAnonInnerClass2() {
349355
Class clazz = new GroovyClassLoader().parseClass('''
350356
@groovy.util.logging.Slf4j
@@ -367,6 +373,29 @@ final class Slf4jTest {
367373
''')
368374
}
369375

376+
// GROOVY-7439
377+
@NotYetImplemented
378+
@ParameterizedTest
379+
@ValueSource(strings=[
380+
'log', // Cannot find matching method Object#debug(String)
381+
'((org.slf4j.Logger) log)' // No such property: log for class: C
382+
])
383+
void testLogTrait(String log) {
384+
assertScript """
385+
@groovy.transform.CompileStatic
386+
@groovy.util.logging.Slf4j
387+
trait T {
388+
void test() {
389+
${log}.debug('trace')
390+
}
391+
}
392+
class C implements T {
393+
}
394+
395+
new C().test()
396+
"""
397+
}
398+
370399
@Test
371400
void testLogGuard() {
372401
Class clazz = new GroovyClassLoader().parseClass('''

src/test/groovy/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,43 +2509,37 @@ final class TraitASTTransformationTest {
25092509
@Test
25102510
void testUseStaticFieldInTraitBody() {
25112511
assertScript shell, '''
2512-
import java.util.logging.Logger
2513-
25142512
trait Loggable {
2515-
2516-
static def LOGGER = Logger.getLogger(this.class.name)
2517-
2513+
private static LOGGER = java.util.logging.Logger.getLogger(this.class.name)
25182514
void info(String msg) {
25192515
LOGGER.info(msg)
25202516
}
25212517
}
2518+
class C implements Loggable {
2519+
}
25222520
2523-
class Test implements Loggable {}
2524-
2525-
def t = new Test()
2526-
t.info('foo')
2521+
def pogo = new C()
2522+
pogo.info('foo')
25272523
'''
25282524
}
25292525

25302526
@Test
25312527
void testUpdateStaticFieldInTraitBody() {
25322528
assertScript shell, '''
25332529
trait Loggable {
2534-
25352530
static int CALLS = 0
2536-
25372531
int call() {
25382532
CALLS += 1
25392533
CALLS
25402534
}
25412535
}
2536+
class C implements Loggable {
2537+
}
25422538
2543-
class Test implements Loggable {}
2544-
2545-
def t = new Test()
2546-
assert t.call() == 1
2547-
assert t.call() == 2
2548-
assert Test.CALLS == 2
2539+
def pogo = new C()
2540+
assert pogo.call() == 1
2541+
assert pogo.call() == 2
2542+
assert pogo.CALLS == 2
25492543
'''
25502544
}
25512545

0 commit comments

Comments
 (0)