Skip to content

Commit

Permalink
add new test
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciferYang committed Oct 22, 2023
1 parent e0fd653 commit 5a38163
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,14 @@ public void testNull() {
assertThrows(NullPointerException.class, () -> CryptoRandomFactory.getCryptoRandom(null));
}

@Test
public void testExceptionInInitializerErrorRandom() throws GeneralSecurityException, IOException {
final Properties properties = new Properties();
String classes = ExceptionInInitializerErrorRandom.class.getName().concat(",")
.concat(CryptoRandomFactory.RandomProvider.JAVA.getClassName());
properties.setProperty(CryptoRandomFactory.CLASSES_KEY, classes);
try (final CryptoRandom random = CryptoRandomFactory.getCryptoRandom(properties)) {
assertEquals(JavaCryptoRandom.class.getName(), random.getClass().getName());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.crypto.random;

import java.io.IOException;
import java.security.GeneralSecurityException;

public class ExceptionInInitializerErrorRandom implements CryptoRandom {

static {
try {
check();
} catch (final GeneralSecurityException e) {
throw new IllegalStateException(e);
}
}

private static void check() throws GeneralSecurityException {
throw new GeneralSecurityException("Native library is not loaded");
}

@Override
public void nextBytes(byte[] bytes) {
}

@Override
public void close() throws IOException {
}
}

0 comments on commit 5a38163

Please sign in to comment.