1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17 /**
18 * @author Vera Y. Petrashkova
19 * @version $Revision$
20 */
21 
22 package tests.security.cert;
23 
24 import junit.framework.TestCase;
25 
26 import org.apache.harmony.security.tests.support.SpiEngUtils;
27 import org.apache.harmony.security.tests.support.cert.MyCertPath;
28 import org.apache.harmony.security.tests.support.cert.MyCertificate;
29 import org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi;
30 
31 import java.io.ByteArrayInputStream;
32 import java.io.ByteArrayOutputStream;
33 import java.io.IOException;
34 import java.io.InputStream;
35 import java.io.ObjectOutputStream;
36 import java.security.NoSuchProviderException;
37 import java.security.Provider;
38 import java.security.cert.CRL;
39 import java.security.cert.CRLException;
40 import java.security.cert.CertPath;
41 import java.security.cert.Certificate;
42 import java.security.cert.CertificateException;
43 import java.security.cert.CertificateFactory;
44 import java.security.cert.CertificateFactorySpi;
45 import java.util.Collection;
46 import java.util.Iterator;
47 import java.util.List;
48 import java.util.Vector;
49 
50 /**
51  * Tests for <code>CertificateFactory</code> class methods and constructor
52  *
53  */
54 public class CertificateFactory1Test extends TestCase {
55 
56     public static final String srvCertificateFactory = "CertificateFactory";
57 
58     private static String defaultProviderName = null;
59 
60     private static Provider defaultProvider = null;
61 
62     private static boolean X509Support = false;
63 
64     public static String defaultType = "X.509";
65 
66     public static final String[] validValues = {
67             "X.509", "x.509" };
68 
69     private final static String[] invalidValues = SpiEngUtils.invalidValues;
70 
71     private static String NotSupportMsg = "";
72 
73     static {
74         defaultProvider = SpiEngUtils.isSupport(defaultType,
75                 srvCertificateFactory);
76         X509Support = (defaultProvider != null);
77         defaultProviderName = (X509Support ? defaultProvider.getName() : null);
78         NotSupportMsg = defaultType.concat(" is not supported");    }
79 
initCertFs()80     private static CertificateFactory[] initCertFs() {
81         if (!X509Support) {
82             fail(NotSupportMsg);
83             return null;
84         }
85         try {
86             CertificateFactory[] certFs = new CertificateFactory[3];
87             certFs[0] = CertificateFactory.getInstance(defaultType);
88             certFs[1] = CertificateFactory.getInstance(defaultType,
89                     defaultProviderName);
90             certFs[2] = CertificateFactory.getInstance(defaultType,
91                     defaultProvider);
92             return certFs;
93         } catch (Exception e) {
94             return null;
95         }
96     }
97 
createMC()98     private static MyCertificate createMC() {
99         byte[] enc = { (byte) 0, (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
100         return new MyCertificate("Test_Test", enc);
101     }
102 
103     /**
104      * Test for <code>getInstance(String type)</code> method
105      * Assertion: returns CertificateFactory if type is X.509
106      */
testCertificateFactory01()107     public void testCertificateFactory01() throws CertificateException {
108         if (!X509Support) {
109             fail(NotSupportMsg);
110             return;
111         }
112         for (int i = 0; i < validValues.length; i++) {
113             CertificateFactory certF = CertificateFactory
114                     .getInstance(validValues[i]);
115             assertEquals("Incorrect type: ", validValues[i], certF.getType());
116         }
117     }
118 
119     /**
120      * Test for <code>getInstance(String type)</code> method
121      * Assertion:
122      * throws NullPointerException when type is null
123      * throws CertificateException when type is not available
124      */
testCertificateFactory02()125     public void testCertificateFactory02() {
126         try {
127             CertificateFactory.getInstance(null);
128             fail("NullPointerException or CertificateException must be thrown when type is null");
129         } catch (CertificateException e) {
130         } catch (NullPointerException e) {
131         }
132         for (int i = 0; i < invalidValues.length; i++) {
133             try {
134                 CertificateFactory.getInstance(invalidValues[i]);
135                 fail("CertificateException must be thrown when type: "
136                         .concat(invalidValues[i]));
137             } catch (CertificateException e) {
138             }
139         }
140     }
141 
142     /**
143      * Test for <code>getInstance(String type, String provider)</code> method
144      * Assertion: throws IllegalArgumentException when provider is null or empty
145      */
testCertificateFactory03()146     public void testCertificateFactory03() throws CertificateException,
147             NoSuchProviderException {
148         if (!X509Support) {
149             fail(NotSupportMsg);
150             return;
151         }
152         String provider = null;
153         for (int i = 0; i < validValues.length; i++) {
154             try {
155                 CertificateFactory.getInstance(validValues[i], provider);
156                 fail("IllegalArgumentException must be thrown when provider is null");
157             } catch (IllegalArgumentException e) {
158             }
159             try {
160                 CertificateFactory.getInstance(validValues[i], "");
161                 fail("IllegalArgumentException  must be thrown when provider is empty");
162             } catch (IllegalArgumentException e) {
163             }
164         }
165     }
166 
167     /**
168      * Test for <code>getInstance(String type, String provider)</code> method
169      * Assertion:
170      * throws NullPointerException when type is null
171      * throws CertificateException when type is not available
172      */
testCertificateFactory04()173     public void testCertificateFactory04() throws NoSuchProviderException {
174         if (!X509Support) {
175             fail(NotSupportMsg);
176             return;
177         }
178         try {
179             CertificateFactory.getInstance(null, defaultProviderName);
180             fail("NullPointerException or CertificateException must be thrown when type is null");
181         } catch (CertificateException e) {
182         } catch (NullPointerException e) {
183         }
184         for (int i = 0; i < invalidValues.length; i++) {
185             try {
186                 CertificateFactory.getInstance(invalidValues[i],
187                         defaultProviderName);
188                 fail("CertificateException must be thrown (type: ".concat(
189                         invalidValues[i]).concat(" provider: ").concat(
190                         defaultProviderName).concat(")"));
191             } catch (CertificateException e) {
192             }
193         }
194     }
195 
196     /**
197      * Test for <code>getInstance(String type, String provider)</code> method
198      * Assertion: returns CertificateFactory when type and provider have valid
199      * values
200      */
testCertificateFactory05()201     public void testCertificateFactory05() throws CertificateException,
202             NoSuchProviderException {
203         if (!X509Support) {
204             fail(NotSupportMsg);
205             return;
206         }
207         CertificateFactory certF;
208         for (int i = 0; i < validValues.length; i++) {
209             certF = CertificateFactory.getInstance(validValues[i],
210                     defaultProviderName);
211             assertEquals("Incorrect type", certF.getType(), validValues[i]);
212             assertEquals("Incorrect provider name", certF.getProvider()
213                     .getName(), defaultProviderName);
214         }
215     }
216 
217     /**
218      * Test for <code>getInstance(String type, Provider provider)</code>
219      * method
220      * Assertion: throws IllegalArgumentException when provider is null
221      */
testCertificateFactory06()222     public void testCertificateFactory06() throws CertificateException {
223         if (!X509Support) {
224             fail(NotSupportMsg);
225             return;
226         }
227         Provider provider = null;
228         for (int i = 0; i < validValues.length; i++) {
229             try {
230                 CertificateFactory.getInstance(validValues[i], provider);
231                 fail("IllegalArgumentException must be thrown  when provider is null");
232             } catch (IllegalArgumentException e) {
233             }
234         }
235     }
236 
237     /**
238      * Test for <code>getInstance(String type, Provider provider)</code>
239      * method
240      * Assertion:
241      * throws NullPointerException when type is null
242      * throws CertificateException when type is not available
243      */
testCertificateFactory07()244     public void testCertificateFactory07() {
245         if (!X509Support) {
246             fail(NotSupportMsg);
247             return;
248         }
249         try {
250             CertificateFactory.getInstance(null, defaultProvider);
251             fail("NullPointerException or CertificateException must be thrown when type is null");
252         } catch (CertificateException e) {
253         } catch (NullPointerException e) {
254         }
255         for (int i = 0; i < invalidValues.length; i++) {
256             try {
257                 CertificateFactory.getInstance(invalidValues[i],
258                         defaultProvider);
259                 fail("CertificateException was not thrown as expected (type:"
260                         .concat(invalidValues[i]).concat(" provider: ").concat(
261                                 defaultProvider.getName()).concat(")"));
262             } catch (CertificateException e) {
263             }
264         }
265     }
266 
267     /**
268      * Test for <code>getInstance(String type, Provider provider)</code>
269      * method
270      * Assertion: returns CertificateFactorythrows when type and provider
271      * have valid values
272      */
testCertificateFactory08()273     public void testCertificateFactory08() throws CertificateException {
274         if (!X509Support) {
275             fail(NotSupportMsg);
276             return;
277         }
278         CertificateFactory certF;
279         for (int i = 0; i < validValues.length; i++) {
280             certF = CertificateFactory.getInstance(validValues[i],
281                     defaultProvider);
282             assertEquals("Incorrect provider", certF.getProvider(),
283                     defaultProvider);
284             assertEquals("Incorrect type", certF.getType(), validValues[i]);
285         }
286     }
287 
288     /**
289      * Test for <code>getCertPathEncodings()</code> method
290      * Assertion: returns encodings
291      */
testCertificateFactory09()292     public void testCertificateFactory09() {
293         if (!X509Support) {
294             fail(NotSupportMsg);
295             return;
296         }
297         CertificateFactory[] certFs = initCertFs();
298         assertNotNull("CertificateFactory objects were not created", certFs);
299         Iterator<String> it1 = certFs[0].getCertPathEncodings();
300         Iterator<String> it2 = certFs[1].getCertPathEncodings();
301         assertEquals("Incorrect encodings", it1.hasNext(), it2.hasNext());
302         while (it1.hasNext()) {
303             it2 = certFs[1].getCertPathEncodings();
304             String s1 = it1.next();
305             boolean yesNo = false;
306             while (it2.hasNext()) {
307                 if (s1.equals(it2.next())) {
308                     yesNo = true;
309                     break;
310                 }
311             }
312             assertTrue("Encoding: ".concat(s1).concat(
313                     " does not define for certF2 CertificateFactory"), yesNo);
314         }
315         it1 = certFs[0].getCertPathEncodings();
316         it2 = certFs[2].getCertPathEncodings();
317         assertEquals("Incorrect encodings", it1.hasNext(), it2.hasNext());
318         while (it1.hasNext()) {
319             it2 = certFs[2].getCertPathEncodings();
320             String s1 = it1.next();
321             boolean yesNo = false;
322             while (it2.hasNext()) {
323                 if (s1.equals(it2.next())) {
324                     yesNo = true;
325                     break;
326                 }
327             }
328             assertTrue("Encoding: ".concat(s1).concat(
329                     " does not define for certF3 CertificateFactory"), yesNo);
330         }
331     }
332 
333     /**
334      * Test for <code>generateCertificate(InputStream inStream)</code>
335      * <code>generateCertificates(InputStream inStream)</code>
336      * <code>generateCRL(InputStream inStream)</code>
337      * <code>generateCRLs(InputStream inStream)</code>
338      * methods
339      * Assertion: throw CertificateException and CRLException when
340      * inStream is null or empty
341      */
testCertificateFactory10()342     public void testCertificateFactory10() {
343         if (!X509Support) {
344             fail(NotSupportMsg);
345             return;
346         }
347         CertificateFactory[] certFs = initCertFs();
348         assertNotNull("CertificateFactory objects were not created", certFs);
349         byte [] bb = {};
350         InputStream is = new ByteArrayInputStream(bb);
351         Collection<?> colCer;
352         Collection<?> colCrl;
353         for (int i = 0; i < certFs.length; i++) {
354             try {
355                 certFs[i].generateCertificate(null);
356                 fail("generateCertificate must thrown CertificateException or NullPointerEXception when input stream is null");
357             } catch (CertificateException e) {
358             } catch (NullPointerException e) {
359             }
360             is = new ByteArrayInputStream(bb);
361             try {
362                 certFs[i].generateCertificates(null);
363                 fail("generateCertificates must throw CertificateException or NullPointerException when input stream is null");
364             } catch (CertificateException e) {
365             } catch (NullPointerException e) {
366             }
367             is = new ByteArrayInputStream(bb);
368             try {
369                 certFs[i].generateCertificate(is);
370             } catch (CertificateException e) {
371             }
372             is = new ByteArrayInputStream(bb);
373             try {
374                 colCer = certFs[i].generateCertificates(is);
375                 if (colCer != null) {
376                     assertTrue("Not empty certificate collection", colCer.isEmpty());
377                 }
378             } catch (CertificateException e) {
379             }
380         }
381         for (int i = 0; i < certFs.length; i++) {
382             try {
383                 certFs[i].generateCRL(null);
384             } catch (CRLException e) {
385             } catch (NullPointerException e) {
386             }
387             try {
388                 colCrl = certFs[i].generateCRLs(null);
389                 if (colCrl != null) {
390                     assertTrue("Not empty CRL collection was returned from null stream", colCrl.isEmpty());
391                 }
392             } catch (CRLException e) {
393             } catch (NullPointerException e) {
394             }
395             is = new ByteArrayInputStream(bb);
396             try {
397                  certFs[i].generateCRL(is);
398             } catch (CRLException e) {
399             }
400             is = new ByteArrayInputStream(bb);
401             try {
402                 certFs[i].generateCRLs(is);
403                 colCrl = certFs[i].generateCRLs(null);
404                 if (colCrl != null) {
405                     assertTrue("Not empty CRL collection was returned from empty stream", colCrl.isEmpty());
406                 }
407             } catch (CRLException e) {
408             }
409         }
410     }
411 
412     /*
413      * Test for <code> generateCertificate(InputStream inStream) </code><code>
414      * generateCertificates(InputStream inStream) </code><code>
415      * generateCRL(InputStream inStream) </code><code>
416      * generateCRLs(InputStream inStream) </code>
417      * methods
418      * Assertion: throw CertificateException and CRLException when inStream
419      * contains incompatible datas
420      */
testCertificateFactory11()421     public void testCertificateFactory11() throws IOException {
422         if (!X509Support) {
423             fail(NotSupportMsg);
424             return;
425         }
426         CertificateFactory[] certFs = initCertFs();
427         assertNotNull("CertificateFactory objects were not created", certFs);
428         MyCertificate mc = createMC();
429         ByteArrayOutputStream os = new ByteArrayOutputStream();
430         ObjectOutputStream oos = new ObjectOutputStream(os);
431         oos.writeObject(mc);
432         oos.flush();
433         oos.close();
434 
435         Certificate cer;
436         Collection<?> colCer;
437         CRL crl;
438         Collection<?> colCrl;
439 
440         byte[] arr = os.toByteArray();
441         ByteArrayInputStream is;
442         for (int i = 0; i < certFs.length; i++) {
443             is = new ByteArrayInputStream(arr);
444             try {
445                 cer = certFs[i].generateCertificate(is);
446                 assertNull("Not null certificate was created", cer);
447             } catch (CertificateException e) {
448             }
449             is = new ByteArrayInputStream(arr);
450             try {
451                 colCer = certFs[i].generateCertificates(is);
452                 if (colCer != null) {
453                     assertTrue("Not empty certificate Collection was created", colCer.isEmpty());
454                 }
455             } catch (CertificateException e) {
456             }
457             is = new ByteArrayInputStream(arr);
458             try {
459                 crl = certFs[i].generateCRL(is);
460                 assertNull("Not null CRL was created", crl);
461             } catch (CRLException e) {
462             }
463             is = new ByteArrayInputStream(arr);
464             try {
465                 colCrl = certFs[i].generateCRLs(is);
466                 if (colCrl != null) {
467                     assertTrue("Not empty CRL Collection was created", colCrl.isEmpty());
468                 }
469             } catch (CRLException e) {
470             }
471         }
472     }
473 
474     /**
475      * Test for <code>generateCertPath(InputStream inStream)</code>
476      * <code>generateCertPath(InputStream inStream, String encoding)</code>
477      * methods
478      * Assertion: throws CertificateException when inStream is null or
479      * when isStream contains invalid datas
480      */
testCertificateFactory12()481     public void testCertificateFactory12() {
482         if (!X509Support) {
483             fail(NotSupportMsg);
484             return;
485         }
486         CertificateFactory[] certFs = initCertFs();
487         assertNotNull("CertificateFactory objects were not created", certFs);
488         InputStream is1 = null;
489         InputStream is2 = new ByteArrayInputStream(new byte[10]);
490 
491         for (int i = 0; i < certFs.length; i++) {
492             try {
493                 certFs[i].generateCertPath(is1);
494                 fail("generateCertificate must thrown CertificateException or NullPointerException when input stream is null");
495             } catch (CertificateException e) {
496             } catch (NullPointerException e) {
497             }
498             try {
499                 certFs[i].generateCertPath(is2);
500                 fail("generateCertificate must thrown CertificateException when input stream contains invalid datas");
501             } catch (CertificateException e) {
502             }
503             Iterator<String> it = certFs[i].getCertPathEncodings();
504             while (it.hasNext()) {
505                 String enc = it.next();
506                 try {
507                     certFs[i].generateCertPath(is1, enc);
508                     fail("generateCertificate must thrown CertificateException or NullPointerException when input stream is null and encodings "
509                             .concat(enc));
510                 } catch (CertificateException e) {
511                 } catch (NullPointerException e) {
512                 }
513                 try {
514                     certFs[i].generateCertPath(is2, enc);
515                     fail("generateCertificate must thrown CertificateException when input stream contains invalid datas  and encodings "
516                             .concat(enc));
517                 } catch (CertificateException e) {
518                 }
519             }
520         }
521     }
522 
523     /**
524      * Test for <code>generateCertPath(InputStream inStream)</code>
525      * <code>generateCertPath(InputStream inStream, String encoding)</code>
526      * methods
527      * Assertion: throw CertificateException when isStream contains invalid datas
528      */
529     // Test passed on RI
testCertificateFactory13()530     public void testCertificateFactory13() throws IOException {
531         if (!X509Support) {
532             fail(NotSupportMsg);
533             return;
534         }
535         CertificateFactory[] certFs = initCertFs();
536         assertNotNull("CertificateFactory objects were not created", certFs);
537         byte[] enc = { (byte) 0, (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
538         MyCertPath mc = new MyCertPath(enc);
539         ByteArrayOutputStream os = new ByteArrayOutputStream();
540 
541         ObjectOutputStream oos = new ObjectOutputStream(os);
542         oos.writeObject(mc);
543         oos.flush();
544         oos.close();
545 
546         byte[] arr = os.toByteArray();
547         ByteArrayInputStream is = new ByteArrayInputStream(arr);
548 
549         for (int i = 0; i < certFs.length; i++) {
550             try {
551                 certFs[i].generateCertPath(is);
552                 fail("CertificateException must be thrown because input stream contains incorrect datas");
553             } catch (CertificateException e) {
554             }
555             Iterator<String> it = certFs[i].getCertPathEncodings();
556             while (it.hasNext()) {
557                 try {
558                     certFs[i].generateCertPath(is, it.next());
559                     fail("CertificateException must be thrown because input stream contains incorrect datas");
560                 } catch (CertificateException e) {
561                 }
562             }
563         }
564     }
565 
566     /**
567      * Test for <code>generateCertPath(List certificates)</code> method
568      * Assertion: throw NullPointerException certificates is null
569      */
testCertificateFactory14()570     public void testCertificateFactory14() throws CertificateException {
571         if (!X509Support) {
572             fail(NotSupportMsg);
573             return;
574         }
575         CertificateFactory[] certFs = initCertFs();
576         assertNotNull("CertificateFactory objects were not created", certFs);
577         List<Certificate> list = null;
578         for (int i = 0; i < certFs.length; i++) {
579             try {
580                 certFs[i].generateCertPath(list);
581                 fail("generateCertificate must thrown CertificateException when list is null");
582             } catch (NullPointerException e) {
583             }
584         }
585     }
586 
587     /**
588      * Test for <code>generateCertPath(List certificates)</code> method
589      * Assertion: returns empty CertPath if certificates is empty
590      */
testCertificateFactory15()591     public void testCertificateFactory15() throws CertificateException {
592         if (!X509Support) {
593             fail(NotSupportMsg);
594             return;
595         }
596         CertificateFactory[] certFs = initCertFs();
597         assertNotNull("CertificateFactory objects were not created", certFs);
598         List<Certificate> list = new Vector<Certificate>();
599         for (int i = 0; i < certFs.length; i++) {
600             CertPath cp = certFs[i].generateCertPath(list);
601             List<? extends Certificate> list1 = cp.getCertificates();
602             assertTrue("List should be empty", list1.isEmpty());
603         }
604     }
605 
606     /**
607      * Test for <code>generateCertPath(List certificates)</code> method
608      * Assertion: throws CertificateException when certificates contains
609      * incorrect Certificate
610      */
testCertificateFactory16()611     public void testCertificateFactory16() {
612         if (!X509Support) {
613             fail(NotSupportMsg);
614             return;
615         }
616         CertificateFactory[] certFs = initCertFs();
617         assertNotNull("CertificateFactory objects were not created", certFs);
618         MyCertificate ms = createMC();
619         List<Certificate> list = new Vector<Certificate>();
620         list.add(ms);
621         for (int i = 0; i < certFs.length; i++) {
622             try {
623                 certFs[i].generateCertPath(list);
624                 fail("CertificateException must be thrown");
625             } catch (CertificateException e) {
626             }
627         }
628     }
629 
630     /**
631      * Test for <code>CertificateFactory</code> constructor
632      * Assertion: returns CertificateFactory object
633      */
testCertificateFactory17()634     public void testCertificateFactory17() throws CRLException {
635         if (!X509Support) {
636             fail(NotSupportMsg);
637             return;
638         }
639         CertificateFactorySpi spi = new MyCertificateFactorySpi();
640         CertificateFactory cf = new myCertificateFactory(spi, defaultProvider,
641                 defaultType);
642         assertEquals("Incorrect type", cf.getType(), defaultType);
643         assertEquals("Incorrect provider", cf.getProvider(), defaultProvider);
644         try {
645             cf.generateCRLs(null);
646             fail("CRLException must be thrown");
647         } catch (CRLException e) {
648         }
649 
650         cf = new myCertificateFactory(null, null, null);
651         assertNull("Incorrect type", cf.getType());
652         assertNull("Incorrect provider", cf.getProvider());
653         try {
654             cf.generateCRLs(null);
655             fail("NullPointerException must be thrown");
656         } catch (NullPointerException e) {
657         }
658     }
659 
660     /**
661      * Test for <code>getType()</code> method
662      */
testCertificateFactory18()663     public void testCertificateFactory18() throws CertificateException {
664         if (!X509Support) {
665             fail(NotSupportMsg);
666             return;
667         }
668         for (int i = 0; i < validValues.length; i++) {
669             try {
670                 CertificateFactory certF = CertificateFactory
671                         .getInstance(validValues[i]);
672                 assertEquals("Incorrect type: ", validValues[i], certF
673                         .getType());
674                 certF = CertificateFactory.getInstance(validValues[i],
675                         defaultProviderName);
676                 assertEquals("Incorrect type", certF.getType(), validValues[i]);
677 
678                 certF = CertificateFactory.getInstance(validValues[i],
679                         defaultProvider);
680                 assertEquals("Incorrect provider", certF.getProvider(),
681                         defaultProvider);
682                 assertEquals("Incorrect type", certF.getType(), validValues[i]);
683 
684             } catch (NoSuchProviderException e) {
685                 fail("Unexpected NoSuchProviderException " + e.getMessage());
686             }
687         }
688     }
689 
690     @SuppressWarnings("cast")
testCertificateFactory19()691     public void testCertificateFactory19() {
692         if (!X509Support) {
693             fail(NotSupportMsg);
694             return;
695         }
696         CertificateFactorySpi spi = new MyCertificateFactorySpi();
697         myCertificateFactory cf;
698         try {
699             cf = new myCertificateFactory(spi, defaultProvider,
700                                       defaultType);
701             assertEquals("Incorrect type", cf.getType(), defaultType);
702             assertEquals("Incorrect provider", cf.getProvider(), defaultProvider);
703             assertTrue(cf instanceof CertificateFactory);
704         } catch (Exception e) {
705             fail("Unexpected exception" + e);
706         }
707 
708         try {
709             cf = new myCertificateFactory(null, null, null);
710         } catch (Exception e) {
711             fail("Unexpected exception" + e);
712         }
713     }
714 }
715 /**
716  * Additional class to verify CertificateFactory constructor
717  */
718 
719 class myCertificateFactory extends CertificateFactory {
720 
myCertificateFactory(CertificateFactorySpi spi, Provider prov, String type)721     public myCertificateFactory(CertificateFactorySpi spi, Provider prov,
722             String type) {
723         super(spi, prov, type);
724     }
725 }
726