/
GroovyMockitoTest.groovy
46 lines (37 loc) · 1 KB
/
GroovyMockitoTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Copyright (c) 2022 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.groovy
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
import static org.mockito.Mockito.verify
@RunWith(MockitoJUnitRunner)
class GroovyMockitoTest {
@Mock Helper helper
@InjectMocks ClassUnderTest classUnderTest
/**
* Test that the Groovy class under test can call methods on a mocked Groovy
* helper class.
*/
@Test
void testCallGroovyFromGroovy() {
classUnderTest.methodUnderTest()
verify(helper).helperMethod()
}
static class ClassUnderTest {
private final Helper helper
ClassUnderTest(Helper helper) {
this.helper = helper
}
void methodUnderTest() {
helper.helperMethod()
}
}
static class Helper {
void helperMethod() { }
}
}