16
16
*/
17
17
package org .apache .logging .log4j .osgi .tests ;
18
18
19
- import static org .junit .Assert .assertEquals ;
20
- import static org .junit .Assert .assertTrue ;
19
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
20
+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
21
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
21
22
22
23
import java .lang .reflect .Method ;
23
24
import java .util .List ;
24
25
import java .util .stream .Collectors ;
25
26
import java .util .stream .Stream ;
26
27
import org .apache .logging .log4j .util .ServiceLoaderUtil ;
27
- import org .junit .Assert ;
28
- import org .junit .Before ;
29
- import org .junit .Rule ;
30
- import org .junit .Test ;
28
+ import org .junit .jupiter .api .BeforeEach ;
29
+ import org .junit .jupiter .api .Test ;
30
+ import org .junit .jupiter .api .extension .RegisterExtension ;
31
31
import org .junit .jupiter .api .function .ThrowingConsumer ;
32
32
import org .osgi .framework .Bundle ;
33
33
import org .osgi .framework .BundleContext ;
@@ -41,14 +41,14 @@ abstract class AbstractLoadBundleTest {
41
41
42
42
private BundleContext bundleContext ;
43
43
44
- @ Rule
45
- public final OsgiRule osgi ;
44
+ @ RegisterExtension
45
+ public final OsgiExt osgi ;
46
46
47
47
AbstractLoadBundleTest (final FrameworkFactory frameworkFactory ) {
48
- this .osgi = new OsgiRule (frameworkFactory );
48
+ this .osgi = new OsgiExt (frameworkFactory );
49
49
}
50
50
51
- @ Before
51
+ @ BeforeEach
52
52
public void before () {
53
53
bundleContext = osgi .getFramework ().getBundleContext ();
54
54
}
@@ -83,9 +83,8 @@ public void testApiCoreStartStopStartStop() throws BundleException {
83
83
84
84
final Bundle api = getApiBundle ();
85
85
final Bundle core = getCoreBundle ();
86
-
87
- Assert .assertEquals ("api is not in INSTALLED state" , Bundle .INSTALLED , api .getState ());
88
- Assert .assertEquals ("core is not in INSTALLED state" , Bundle .INSTALLED , core .getState ());
86
+ assertEquals (Bundle .INSTALLED , api .getState (), "api is not in INSTALLED state" );
87
+ assertEquals (Bundle .INSTALLED , core .getState (), "core is not in INSTALLED state" );
89
88
90
89
// 1st start-stop
91
90
doOnBundlesAndVerifyState (Bundle ::start , Bundle .ACTIVE , api , core );
@@ -125,7 +124,7 @@ public void testClassNotFoundErrorLogger() throws BundleException {
125
124
throw error0 ;
126
125
}
127
126
}
128
- assertEquals (String .format ("`%s` bundle state mismatch" , core ), Bundle . ACTIVE , core . getState ( ));
127
+ assertEquals (Bundle . ACTIVE , core . getState (), String .format ("`%s` bundle state mismatch" , core ));
129
128
130
129
doOnBundlesAndVerifyState (Bundle ::stop , Bundle .RESOLVED , core , api );
131
130
doOnBundlesAndVerifyState (Bundle ::uninstall , Bundle .UNINSTALLED , core , api );
@@ -148,14 +147,14 @@ public void testLog4J12Fragement() throws BundleException, ReflectiveOperationEx
148
147
final Class <?> levelClassFrom12API = core .loadClass ("org.apache.log4j.Level" );
149
148
final Class <?> levelClassFromAPI = core .loadClass ("org.apache.logging.log4j.Level" );
150
149
151
- Assert .assertEquals (
152
- "expected 1.2 API Level to have the same class loader as Core" ,
150
+ assertEquals (
153
151
levelClassFrom12API .getClassLoader (),
154
- coreClassFromCore .getClassLoader ());
155
- Assert . assertNotEquals (
156
- "expected 1.2 API Level NOT to have the same class loader as API Level" ,
152
+ coreClassFromCore .getClassLoader (),
153
+ "expected 1.2 API Level to have the same class loader as Core" );
154
+ assertNotEquals (
157
155
levelClassFrom12API .getClassLoader (),
158
- levelClassFromAPI .getClassLoader ());
156
+ levelClassFromAPI .getClassLoader (),
157
+ "expected 1.2 API Level NOT to have the same class loader as API Level" );
159
158
160
159
doOnBundlesAndVerifyState (Bundle ::stop , Bundle .RESOLVED , core , api );
161
160
doOnBundlesAndVerifyState (Bundle ::uninstall , Bundle .UNINSTALLED , compat , core , api );
@@ -171,8 +170,7 @@ public void testServiceLoader() throws BundleException, ReflectiveOperationExcep
171
170
final Bundle apiTests = getApiTestsBundle ();
172
171
173
172
final Class <?> osgiServiceLocator = api .loadClass ("org.apache.logging.log4j.util.OsgiServiceLocator" );
174
- assertTrue ("OsgiServiceLocator is active" , (boolean )
175
- osgiServiceLocator .getMethod ("isAvailable" ).invoke (null ));
173
+ assertTrue ((boolean ) osgiServiceLocator .getMethod ("isAvailable" ).invoke (null ), "OsgiServiceLocator is active" );
176
174
177
175
doOnBundlesAndVerifyState (Bundle ::start , Bundle .ACTIVE , api , core , apiTests );
178
176
@@ -202,7 +200,7 @@ private static void doOnBundlesAndVerifyState(
202
200
final String message = String .format ("operation failure for bundle `%s`" , bundle );
203
201
throw new RuntimeException (message , error );
204
202
}
205
- assertEquals (String .format ("`%s` bundle state mismatch" , bundle ), expectedState , bundle . getState ( ));
203
+ assertEquals (expectedState , bundle . getState (), String .format ("`%s` bundle state mismatch" , bundle ));
206
204
}
207
205
}
208
206
}
0 commit comments