DefaultIdentityCertServiceAdapter implements
    IdentityCertServiceAdapter { @Override public IdentityCertificate generateIdentityCert(Consumer consumer) throws GeneralSecurityException, IOException { if (log.isDebugEnabled()) { log.debug("Generating identity cert for consumer: " + consumer.getUuid()); } IdentityCertificate certificate = null; if (consumer.getIdCert() != null) { certificate = idCertCurator.get(consumer.getIdCert().getId()); } if (certificate != null) { return certificate; } return generate(consumer); } @SuppressWarnings("unchecked") @Inject  DefaultIdentityCertServiceAdapter(PKIUtility pki,
        IdentityCertificateCurator identityCertCurator,
        KeyPairCurator keyPairCurator,
        CertificateSerialCurator serialCurator,
        @Named("endDateGenerator") Function endDtGen); @Override void deleteIdentityCert(Consumer consumer); @Override IdentityCertificate generateIdentityCert(Consumer consumer); @Override IdentityCertificate regenerateIdentityCert(Consumer consumer);  }
@Test public void testReturnExisting() throws GeneralSecurityException, IOException { Consumer consumer = mock(Consumer.class); IdentityCertificate mockic = mock(IdentityCertificate.class); when(consumer.getIdCert()).thenReturn(mockic); when(idcur.get(mockic.getId())).thenReturn(mockic); when(idcur.get(consumer.getId())).thenReturn(mockic); IdentityCertificate ic = dicsa.generateIdentityCert(consumer); assertNotNull(ic); assertEquals(ic, mockic); }