@TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "newInstance", args = {java.lang.Object.class}) public void testNewInstance() throws Exception { Provider p = new MyProvider(); Provider.Service s = new Provider.Service( p, "SecureRandom", "algorithm", "org.apache.harmony.security.tests.support.RandomImpl", null, null); Object o = s.newInstance(null); assertTrue("incorrect instance", o instanceof RandomImpl); try { o = s.newInstance(new Object()); fail("No expected NoSuchAlgorithmException"); } catch (NoSuchAlgorithmException e) { } }
/** * Get a password factory instance. The returned password factory object will implement the given * algorithm. * * @param algorithm the name of the algorithm * @param providerSupplier the provider supplier to search * @return a password factory instance * @throws NoSuchAlgorithmException if the given algorithm has no available implementations */ public static PasswordFactory getInstance(String algorithm, Supplier<Provider[]> providerSupplier) throws NoSuchAlgorithmException { for (Provider provider : providerSupplier.get()) { final Provider.Service service = provider.getService("PasswordFactory", algorithm); if (service != null) { return new PasswordFactory( (PasswordFactorySpi) service.newInstance(null), provider, algorithm); } } throw log.noSuchAlgorithmInvalidAlgorithm(algorithm); }
/** * Get a password factory instance. The returned password factory object will implement the given * algorithm. * * @param algorithm the name of the algorithm * @param provider the provider to use * @return a password factory instance * @throws NoSuchAlgorithmException if the given algorithm has no available implementations */ public static PasswordFactory getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { final Provider.Service service = provider.getService("PasswordFactory", algorithm); if (service == null) throw log.noSuchAlgorithmInvalidAlgorithm(algorithm); return new PasswordFactory((PasswordFactorySpi) service.newInstance(null), provider, algorithm); }