mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-18 02:12:06 +01:00
JUnit test the AlgorithmSuite class
This commit is contained in:
parent
733dcf0a7e
commit
4947f17842
2 changed files with 80 additions and 3 deletions
|
@ -22,6 +22,10 @@ import java.util.LinkedHashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The {@link AlgorithmSuite} class is consulted when new OpenPGP keys are being generated to set
|
||||
* preferred algorithms on the key.
|
||||
*/
|
||||
public class AlgorithmSuite {
|
||||
|
||||
private static AlgorithmSuite defaultAlgorithmSuite = new AlgorithmSuite(
|
||||
|
@ -63,7 +67,7 @@ public class AlgorithmSuite {
|
|||
|
||||
public int[] getSymmetricKeyAlgorithmIds() {
|
||||
int[] array = new int[symmetricKeyAlgorithms.size()];
|
||||
List<SymmetricKeyAlgorithm> list = new ArrayList<>(symmetricKeyAlgorithms);
|
||||
List<SymmetricKeyAlgorithm> list = new ArrayList<>(getSymmetricKeyAlgorithms());
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = list.get(i).getAlgorithmId();
|
||||
}
|
||||
|
@ -80,7 +84,7 @@ public class AlgorithmSuite {
|
|||
|
||||
public int[] getHashAlgorithmIds() {
|
||||
int[] array = new int[hashAlgorithms.size()];
|
||||
List<HashAlgorithm> list = new ArrayList<>(hashAlgorithms);
|
||||
List<HashAlgorithm> list = new ArrayList<>(getHashAlgorithms());
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = list.get(i).getAlgorithmId();
|
||||
}
|
||||
|
@ -97,7 +101,7 @@ public class AlgorithmSuite {
|
|||
|
||||
public int[] getCompressionAlgorithmIds() {
|
||||
int[] array = new int[compressionAlgorithms.size()];
|
||||
List<CompressionAlgorithm> list = new ArrayList<>(compressionAlgorithms);
|
||||
List<CompressionAlgorithm> list = new ArrayList<>(getCompressionAlgorithms());
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = list.get(i).getAlgorithmId();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright 2021 Paul Schaub.
|
||||
*
|
||||
* Licensed 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.pgpainless.algorithm;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AlgorithmSuiteTest {
|
||||
|
||||
private AlgorithmSuite suite;
|
||||
|
||||
@BeforeEach
|
||||
public void resetEmptyAlgorithmSuite() {
|
||||
suite = new AlgorithmSuite(
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSymmetricAlgorithmsTest() {
|
||||
List<SymmetricKeyAlgorithm> algorithmList = Arrays.asList(
|
||||
SymmetricKeyAlgorithm.AES_128, SymmetricKeyAlgorithm.AES_192, SymmetricKeyAlgorithm.AES_256
|
||||
);
|
||||
|
||||
suite.setSymmetricKeyAlgorithms(algorithmList);
|
||||
|
||||
assertEquals(algorithmList, new ArrayList<>(suite.getSymmetricKeyAlgorithms()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHashAlgorithmsTest() {
|
||||
List<HashAlgorithm> algorithmList = Arrays.asList(
|
||||
HashAlgorithm.SHA256, HashAlgorithm.SHA384, HashAlgorithm.SHA512
|
||||
);
|
||||
|
||||
suite.setHashAlgorithms(algorithmList);
|
||||
|
||||
assertEquals(algorithmList, new ArrayList<>(suite.getHashAlgorithms()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCompressionAlgorithmsTest() {
|
||||
List<CompressionAlgorithm> algorithmList = Arrays.asList(
|
||||
CompressionAlgorithm.ZLIB, CompressionAlgorithm.ZIP, CompressionAlgorithm.BZIP2
|
||||
);
|
||||
|
||||
suite.setCompressionAlgorithms(algorithmList);
|
||||
|
||||
assertEquals(algorithmList, new ArrayList<>(suite.getCompressionAlgorithms()));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue