From ff4b0c4a03d08543a61bc0b5860d418802a3f218 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 3 Jul 2023 15:03:59 +0200 Subject: [PATCH] Atomize CertificationSetTest test cases and use backtick notation for test names --- .../wot/dijkstra/CertificationSetTest.kt | 52 +++++++++++++++---- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/CertificationSetTest.kt b/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/CertificationSetTest.kt index 200cad65..be99c830 100644 --- a/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/CertificationSetTest.kt +++ b/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/CertificationSetTest.kt @@ -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 "]!!.contains(aliceSignsBobUserId) } + } + @Test + fun `verify that add()ing another Certification object fails if the issuer mismatches`() { + val set = CertificationSet.empty(alice, bob) assertThrows { set.add(charlieSignsBob) } + } + + @Test + fun `verify that add()ing another Certification object fails if the target mismatches`() { + val set = CertificationSet.empty(alice, bob) assertThrows { 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 "]!!.contains(aliceSignsBobUserId) } - - assertThrows { 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 { 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 { 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)