mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-16 09:11:08 +01:00
Increase test coverage
This commit is contained in:
parent
04be9d9dcc
commit
0c5cad677c
1 changed files with 27 additions and 1 deletions
|
|
@ -11,6 +11,7 @@ import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -19,6 +20,7 @@ import pgp.cert_d.SharedPGPCertificateDirectory;
|
||||||
import pgp.cert_d.exception.BadDataException;
|
import pgp.cert_d.exception.BadDataException;
|
||||||
import pgp.cert_d.exception.BadNameException;
|
import pgp.cert_d.exception.BadNameException;
|
||||||
import pgp.certificate_store.CertificateStore;
|
import pgp.certificate_store.CertificateStore;
|
||||||
|
import pgp.certificate_store.MergeCallback;
|
||||||
|
|
||||||
public class SharedPGPCertificateDirectoryAdapterMockTest {
|
public class SharedPGPCertificateDirectoryAdapterMockTest {
|
||||||
|
|
||||||
|
|
@ -27,9 +29,13 @@ public class SharedPGPCertificateDirectoryAdapterMockTest {
|
||||||
private static final String badData = "badData";
|
private static final String badData = "badData";
|
||||||
|
|
||||||
private static CertificateStore store;
|
private static CertificateStore store;
|
||||||
|
private static MergeCallback mergeCallback;
|
||||||
|
private static InputStream inputStream;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void mockComponents() throws BadNameException, IOException, BadDataException {
|
public static void mockComponents() throws BadNameException, IOException, BadDataException, InterruptedException {
|
||||||
|
mergeCallback = mock(MergeCallback.class);
|
||||||
|
inputStream = mock(InputStream.class);
|
||||||
SharedPGPCertificateDirectory mocked = mock(SharedPGPCertificateDirectory.class);
|
SharedPGPCertificateDirectory mocked = mock(SharedPGPCertificateDirectory.class);
|
||||||
store = new SharedPGPCertificateDirectoryAdapter(mocked);
|
store = new SharedPGPCertificateDirectoryAdapter(mocked);
|
||||||
// bad name
|
// bad name
|
||||||
|
|
@ -46,20 +52,40 @@ public class SharedPGPCertificateDirectoryAdapterMockTest {
|
||||||
.thenThrow(new BadDataException());
|
.thenThrow(new BadDataException());
|
||||||
when(mocked.getByFingerprintIfChanged(eq(badData), any()))
|
when(mocked.getByFingerprintIfChanged(eq(badData), any()))
|
||||||
.thenThrow(new BadDataException());
|
.thenThrow(new BadDataException());
|
||||||
|
when(mocked.insert(any(), any()))
|
||||||
|
.thenThrow(new BadDataException());
|
||||||
|
when(mocked.tryInsert(any(), any()))
|
||||||
|
.thenThrow(new BadDataException());
|
||||||
|
when(mocked.insertWithSpecialName(eq(invalidSpecialName), any(), any()))
|
||||||
|
.thenThrow(new BadDataException());
|
||||||
|
when(mocked.tryInsertWithSpecialName(eq(invalidSpecialName), any(), any()))
|
||||||
|
.thenThrow(new BadDataException());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetUsingFingerprint_BadNameIsMappedToIAE() {
|
public void testGetUsingFingerprint_BadNameIsMappedToIAE() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> store.getCertificate(invalidFingerprint));
|
assertThrows(IllegalArgumentException.class, () -> store.getCertificate(invalidFingerprint));
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> store.getCertificateIfChanged(invalidFingerprint, "tag"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetUsingSpecialName_BadNameIsMappedToIAE() {
|
public void testGetUsingSpecialName_BadNameIsMappedToIAE() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> store.getCertificate(invalidSpecialName));
|
assertThrows(IllegalArgumentException.class, () -> store.getCertificate(invalidSpecialName));
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> store.getCertificateIfChanged(invalidSpecialName, "tag"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGet_BadDataIsMappedToIOE() {
|
public void testGet_BadDataIsMappedToIOE() {
|
||||||
assertThrows(IOException.class, () -> store.getCertificate(badData));
|
assertThrows(IOException.class, () -> store.getCertificate(badData));
|
||||||
|
assertThrows(IOException.class, () -> store.getCertificateIfChanged(badData, "tag"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsert_BadDataIsMappedToIOE() {
|
||||||
|
assertThrows(IOException.class, () -> store.insertCertificate(inputStream, mergeCallback));
|
||||||
|
assertThrows(IOException.class, () -> store.insertCertificateBySpecialName(invalidSpecialName, inputStream, mergeCallback));
|
||||||
|
|
||||||
|
assertThrows(IOException.class, () -> store.tryInsertCertificate(inputStream, mergeCallback));
|
||||||
|
assertThrows(IOException.class, () -> store.tryInsertCertificateBySpecialName(invalidSpecialName, inputStream, mergeCallback));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue