mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-16 09:11:08 +01:00
Add JUnit tests
This commit is contained in:
parent
2e6a1dcbc5
commit
b3ca06584b
5 changed files with 137 additions and 7 deletions
|
|
@ -1,3 +1,7 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.cert_d;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
|
|||
|
|
@ -11,16 +11,17 @@ import java.io.FileInputStream;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.List;
|
||||
|
||||
import pgp.cert_d.exception.BadDataException;
|
||||
import pgp.cert_d.exception.BadNameException;
|
||||
import pgp.cert_d.exception.NotAStoreException;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.certificate_store.MergeCallback;
|
||||
import pgp.certificate_store.CertificateReaderBackend;
|
||||
import pgp.certificate_store.MergeCallback;
|
||||
|
||||
public class SharedPGPCertificateDirectoryImpl implements SharedPGPCertificateDirectory {
|
||||
|
||||
|
|
@ -237,7 +238,7 @@ public class SharedPGPCertificateDirectoryImpl implements SharedPGPCertificateDi
|
|||
public Iterator<Certificate> items() {
|
||||
return new Iterator<Certificate>() {
|
||||
|
||||
private final Queue<Lazy<Certificate>> certificateQueue = new SynchronousQueue<>();
|
||||
private final List<Lazy<Certificate>> certificateQueue = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
// Constructor... wtf.
|
||||
{
|
||||
|
|
@ -283,7 +284,7 @@ public class SharedPGPCertificateDirectoryImpl implements SharedPGPCertificateDi
|
|||
@Override
|
||||
public Certificate next() {
|
||||
try {
|
||||
return certificateQueue.poll().get();
|
||||
return certificateQueue.remove(0).get();
|
||||
} catch (BadDataException e) {
|
||||
throw new AssertionError("Could not retrieve item: " + e.getMessage());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
|
|
@ -19,4 +20,24 @@ public class BaseDirectoryProviderTest {
|
|||
File baseDir = BaseDirectoryProvider.getDefaultBaseDirForOS("linux");
|
||||
assertTrue(baseDir.getAbsolutePath().endsWith("/.local/share/pgp.cert.d"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDefaultBaseDir_Windows() {
|
||||
assumeTrue(System.getProperty("os.name").toLowerCase().contains("win"));
|
||||
File baseDir = BaseDirectoryProvider.getDefaultBaseDirForOS("Windows");
|
||||
assertTrue(baseDir.getAbsolutePath().endsWith("\\Roaming\\pgp.cert.d"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDefaultBaseDir_Mac() {
|
||||
assumeTrue(System.getProperty("os.name").toLowerCase().contains("mac"));
|
||||
File baseDir = BaseDirectoryProvider.getDefaultBaseDirForOS("Mac");
|
||||
assertTrue(baseDir.getAbsolutePath().endsWith("/Library/Application Support/pgp.cert.d"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDefaultBaseDirNotNull() {
|
||||
File baseDir = BaseDirectoryProvider.getDefaultBaseDir();
|
||||
assertNotNull(baseDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public class FilenameResolverTest {
|
|||
File subDir = new File(baseDir, "d1");
|
||||
File expected = new File(subDir, "a66e1a23b182c9980f788cfbfcc82a015e7330");
|
||||
|
||||
assertEquals(resolver.getCertFileByFingerprint(fingerprint).getAbsolutePath(), expected.getAbsolutePath());
|
||||
assertEquals(expected.getAbsolutePath(), resolver.getCertFileByFingerprint(fingerprint).getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -44,7 +44,7 @@ public class FilenameResolverTest {
|
|||
File subDir = new File(baseDir, "eb");
|
||||
File expected = new File(subDir, "85bb5fa33a75e15e944e63f231550c4f47e38e");
|
||||
|
||||
assertEquals(resolver.getCertFileByFingerprint(fingerprint).getAbsolutePath(), expected.getAbsolutePath());
|
||||
assertEquals(expected.getAbsolutePath(), resolver.getCertFileByFingerprint(fingerprint).getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -63,4 +63,18 @@ public class FilenameResolverTest {
|
|||
public void testGetFileForNullFingerprint() {
|
||||
assertThrows(NullPointerException.class, () -> resolver.getCertFileByFingerprint(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFileForSpecialName() throws BadNameException {
|
||||
String specialName = "trust-root";
|
||||
File expected = new File(baseDir, "trust-root");
|
||||
|
||||
assertEquals(expected, resolver.getCertFileBySpecialName(specialName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFileForInvalidSpecialName() {
|
||||
String invalidSpecialName = "invalid";
|
||||
assertThrows(BadNameException.class, () -> resolver.getCertFileBySpecialName(invalidSpecialName));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue