@Test
public void shouldCleanUpOrphanedAssociationWithObject() {

    // Create validation run
    RsyncRepositoryValidationRun orphanValidationRun = wtx(tx -> new RsyncRepositoryValidationRun());
    wtx0(tx -> getValidationRuns().add(tx, orphanValidationRun));
    // Create RPKI Object
    RpkiObject associatedAndDeletedObject = new RpkiObject(
            new X509ResourceCertificateBuilder()
                    .withResources(IpResourceSet.parse("10.0.0.0/8"))
                    .withIssuerDN(testTA1.getCertificate().getSubject())
                    .withSubjectDN(new X500Principal("CN=orphan"))
                    .withSerial(TrustAnchorsFactory.nextSerial())
                    .withPublicKey(KEY_PAIR_FACTORY.generate().getPublic())
                    .withSigningKeyPair(KEY_PAIR_FACTORY.generate())
                    .withValidityPeriod(new ValidityPeriod(DateTime.now(), DateTime.now().plusYears(1)))
                    .build()
    );
    wtx0(tx -> getRpkiObjects().put(tx, associatedAndDeletedObject));
    // Associate validation run with object
    wtx0(tx -> getValidationRuns().associate(tx, orphanValidationRun, associatedAndDeletedObject));
    // Delete object, validation run becomes orphan.
    wtx0(tx -> getRpkiObjects().delete(tx, associatedAndDeletedObject));
    // It should then be deleted.
    AtomicInteger orphanCount = subject.cleanupValidationRuns().getRight();
    assertThat(orphanCount.get()).isEqualTo(1);
}