BAEL-4488 Convert class with main to UnitTest class
This commit is contained in:
parent
0976c32038
commit
15ba49d0f4
|
@ -1,32 +1,35 @@
|
|||
package com.baeldung.cipher;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.security.Provider;
|
||||
import java.security.Security;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AvailableCiphers {
|
||||
public static void main(String[] args) {
|
||||
printAllCiphers();
|
||||
printCompatibleCiphers();
|
||||
}
|
||||
public class AvailableCiphersUnitTest {
|
||||
private final Logger logger = LoggerFactory.getLogger(AvailableCiphersUnitTest.class);
|
||||
|
||||
private static void printAllCiphers() {
|
||||
@Test
|
||||
public void whenGetServices_thenGetAllCipherAlgorithms() {
|
||||
for (Provider provider : Security.getProviders()) {
|
||||
for (Provider.Service service : provider.getServices()) {
|
||||
System.out.println(service.getAlgorithm());
|
||||
logger.info(service.getAlgorithm());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void printCompatibleCiphers() {
|
||||
@Test
|
||||
public void whenGetServicesWithFilter_thenGetAllCompatibleCipherAlgorithms() {
|
||||
List<String> algorithms = Arrays.stream(Security.getProviders())
|
||||
.flatMap(provider -> provider.getServices().stream())
|
||||
.filter(service -> "Cipher".equals(service.getType()))
|
||||
.map(Provider.Service::getAlgorithm)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
algorithms.forEach(System.out::println);
|
||||
algorithms.forEach(logger::info);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue