2727import org .junit .rules .TestRule ;
2828import org .junit .rules .TestWatcher ;
2929import org .junit .runner .Description ;
30+ import org .junit .runners .model .Statement ;
3031import org .junit .Test ;
3132import org .junit .BeforeClass ;
3233
@@ -128,6 +129,24 @@ private static boolean isAndroid() {
128129 @ Rule (order = Integer .MIN_VALUE )
129130 public TestRule testWatcher = TimedTestWatcher .create ();
130131
132+ /* Rule to check if cert files are available, skips tests if not. */
133+ @ Rule (order = Integer .MIN_VALUE + 1 )
134+ public TestRule certFilesAvailable = new TestRule () {
135+ @ Override
136+ public Statement apply (final Statement base ,
137+ Description description ) {
138+ return new Statement () {
139+ @ Override
140+ public void evaluate () throws Throwable {
141+ File f = new File (jksCaServerRSA2048 );
142+ Assume .assumeTrue ("Test cert files not available: " +
143+ jksCaServerRSA2048 , f .exists ());
144+ base .evaluate ();
145+ }
146+ };
147+ }
148+ };
149+
131150 @ BeforeClass
132151 public static void testSetupAndProviderInstallation ()
133152 throws Exception , NoSuchProviderException {
@@ -145,7 +164,7 @@ public static void testSetupAndProviderInstallation()
145164
146165 if (isAndroid ()) {
147166 /* On Android, example certs/keys/KeyStores are on SD card */
148- certPre = "/sdcard /" ;
167+ certPre = "/data/local/tmp /" ;
149168
150169 /* On Android, KeyStore files are .bks and type is BKS */
151170 jksExt = ".bks" ;
@@ -188,12 +207,6 @@ public static void testSetupAndProviderInstallation()
188207
189208 crlDer =
190209 certPre .concat ("examples/certs/crl/crl.der" );
191-
192- /* Test if file exists, if not might be running on Android.
193- * Skip tests gracefully if cert files not available. */
194- File f = new File (jksCaServerRSA2048 );
195- Assume .assumeTrue ("Test cert files not available: " + jksCaServerRSA2048 ,
196- f .exists ());
197210 }
198211
199212 /**
0 commit comments