1
1
package tools .jackson .module .osgi ;
2
2
3
- import static org .junit .Assert .assertEquals ;
4
- import static org .junit .Assert .assertNotNull ;
5
- import static org .junit .Assert .assertNull ;
6
- import static org .junit .Assert .fail ;
7
- import static org .mockito .ArgumentMatchers .any ;
8
- import static org .mockito .ArgumentMatchers .anyString ;
9
- import static org .mockito .ArgumentMatchers .eq ;
10
- import static org .mockito .Mockito .doReturn ;
11
- import static org .mockito .Mockito .doThrow ;
12
- import static org .mockito .Mockito .mock ;
13
- import static org .mockito .Mockito .times ;
14
- import static org .mockito .Mockito .when ;
3
+ import java .util .stream .Stream ;
15
4
16
- import java .util .Arrays ;
17
- import java .util .Collection ;
5
+ import org .junit .jupiter .api .BeforeEach ;
6
+ import org .junit .jupiter .params .ParameterizedTest ;
7
+ import org .junit .jupiter .params .provider .MethodSource ;
18
8
19
- import org .junit .Before ;
20
- import org .junit .Ignore ;
21
- import org .junit .Test ;
22
- import org .junit .runner .RunWith ;
23
- import org .junit .runners .Parameterized ;
24
- import org .junit .runners .Parameterized .Parameter ;
25
- import org .junit .runners .Parameterized .Parameters ;
26
9
import org .mockito .Mockito ;
27
10
import org .osgi .framework .BundleContext ;
28
11
import org .osgi .framework .Filter ;
34
17
import tools .jackson .databind .ObjectMapper ;
35
18
import tools .jackson .databind .json .JsonMapper ;
36
19
37
- @ RunWith (value = Parameterized .class )
38
- @ Ignore ("Does not work on JDK 17/Mockito 5.x" )
20
+ import static org .junit .jupiter .api .Assertions .*;
21
+
22
+ import static org .mockito .ArgumentMatchers .any ;
23
+ import static org .mockito .ArgumentMatchers .anyString ;
24
+ import static org .mockito .ArgumentMatchers .eq ;
25
+ import static org .mockito .Mockito .doReturn ;
26
+ import static org .mockito .Mockito .doThrow ;
27
+ import static org .mockito .Mockito .mock ;
28
+ import static org .mockito .Mockito .times ;
29
+ import static org .mockito .Mockito .when ;
30
+
39
31
public class InjectOsgiServiceTest
40
32
{
41
33
private static final String OSGI_FILTER = "osgi.filter" ;
42
34
43
35
private BundleContext bundleContext ;
44
36
45
37
private ObjectMapper mapper ;
46
-
47
- @ Parameter
48
- public Class <?> beanClass ;
49
-
50
- @ Parameters
51
- public static Collection < Class <? extends VerifyableBean >> data () {
52
- return Arrays . asList (
53
- BeanWithServiceInConstructor .class ,
54
- BeanWithFilter .class ,
55
- BeanWithServiceInField .class ,
56
- BeanWithNotFoundService . class );
38
+
39
+ public static Stream < Class <? extends VerifyableBean >> data () {
40
+ // 18-Jan-2025, tatu: Looks like we'll mostly fail to inject Service
41
+ // in Jackson 3.0/JDK 17/JUnit 5/JPMS (not sure which part matters most;
42
+ // possibly JPMS). So comment out ones that'd fail
43
+ return Stream . of (
44
+ //BeanWithServiceInConstructor.class,
45
+ BeanWithFilter .class
46
+ //BeanWithServiceInField .class,
47
+ //BeanWithNotFoundService .class
48
+ );
57
49
}
58
50
59
51
@ SuppressWarnings ("unchecked" )
60
- @ Before
52
+ @ BeforeEach
61
53
public void setUp () throws Exception
62
54
{
63
55
bundleContext = mock (BundleContext .class );
@@ -73,8 +65,10 @@ public void setUp() throws Exception
73
65
.build ();
74
66
}
75
67
76
- @ Test
77
- public void testServiceIsInjected () throws Exception
68
+ @ MethodSource ("data" )
69
+ @ ParameterizedTest
70
+ public void testServiceIsInjected (Class <?> beanClass )
71
+ throws Exception
78
72
{
79
73
// ACTION
80
74
VerifyableBean result = mapper .reader ().forType (beanClass )
@@ -98,7 +92,7 @@ public static abstract class VerifyableBean
98
92
{
99
93
public String field ;
100
94
101
- protected Service service ;
95
+ public Service service ;
102
96
103
97
public boolean verify (BundleContext bundleContext )
104
98
{
@@ -135,7 +129,7 @@ public boolean verify(BundleContext bundleContext)
135
129
public static class BeanWithServiceInField extends VerifyableBean
136
130
{
137
131
@ JacksonInject
138
- private Service service2 ;
132
+ public Service service2 ;
139
133
140
134
@ Override
141
135
public boolean verify (BundleContext bundleContext )
0 commit comments