1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-26 13:34:49 +02:00

Atomize CertificationSetTest test cases and use backtick notation for test names

This commit is contained in:
Paul Schaub 2023-07-03 15:03:59 +02:00
parent f410fb9bfb
commit ff4b0c4a03
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -23,15 +23,15 @@ class CertificationSetTest {
private val charlieSignsBob = Certification(charlie, null, bob, Date())
@Test
fun emptyCertificationSet() {
fun `verify that properties of an empty CertificationSet are also empty`() {
val empty = CertificationSet.empty(alice, bob)
assertTrue { empty.certifications.isEmpty() }
assert(empty.certifications.isEmpty())
assertEquals(alice, empty.issuer)
assertEquals(bob, empty.target)
}
@Test
fun addCertification() {
fun `verify that add()ing Certification objects works if issuer and target match that of the CertificationSet`() {
val set = CertificationSet.empty(alice, bob)
set.add(aliceSignsBob)
@ -44,33 +44,63 @@ class CertificationSetTest {
assertTrue {
set.certifications["Bob <bob@example.org>"]!!.contains(aliceSignsBobUserId)
}
}
@Test
fun `verify that add()ing another Certification object fails if the issuer mismatches`() {
val set = CertificationSet.empty(alice, bob)
assertThrows<IllegalArgumentException> { set.add(charlieSignsBob) }
}
@Test
fun `verify that add()ing another Certification object fails if the target mismatches`() {
val set = CertificationSet.empty(alice, bob)
assertThrows<IllegalArgumentException> { set.add(aliceSignsCharlie) }
}
@Test
fun mergeCertificationSets() {
fun `verify that merge()ing another CertificationSet works if issuer and target match that of the CertificationSet`() {
val set = CertificationSet.fromCertification(aliceSignsBob)
val others = CertificationSet.fromCertification(aliceSignsBobUserId)
val mismatch = CertificationSet.fromCertification(charlieSignsBob)
set.merge(others)
assertEquals(2, set.certifications.size)
assertTrue { set.certifications[null]!!.contains(aliceSignsBob) }
assertTrue { set.certifications["Bob <bob@example.org>"]!!.contains(aliceSignsBobUserId) }
assertThrows<IllegalArgumentException> { set.merge(mismatch) }
set.merge(set)
assertEquals(2, set.certifications.size)
}
@Test
fun testToString() {
fun `verify that merge()ing another CertificationSet with mismatched issuer fails`() {
val set = CertificationSet.fromCertification(aliceSignsBob)
val issuerMismatch = CertificationSet.fromCertification(charlieSignsBob)
assertThrows<IllegalArgumentException> { set.merge(issuerMismatch) }
}
@Test
fun `verify that merge()ing another CertificationSet with mismatched target fails`() {
val set = CertificationSet.fromCertification(aliceSignsBob)
val targetMismatch = CertificationSet.fromCertification(aliceSignsCharlie)
assertThrows<IllegalArgumentException> { set.merge(targetMismatch) }
}
@Test
fun `verify that merge()ing a CertificationSet with itself is idempotent`() {
val set = CertificationSet.fromCertification(aliceSignsBob)
assertEquals(1, set.certifications.size)
set.merge(set)
assertEquals(1, set.certifications.size)
}
@Test
fun `verify that toString() of an empty CertificationSet is the empty string`() {
val empty = CertificationSet.empty(alice, bob)
assertEquals("", empty.toString())
}
@Test
fun `verify that toString() of a CertificationSet with two Certifications matches our expectations`() {
val twoCerts = CertificationSet.fromCertification(aliceSignsBob)
twoCerts.add(aliceSignsBobUserId)