DefaultProductServiceAdapter implements ProductServiceAdapter { @Override public CertificateInfo getProductCertificate(String ownerKey, String productId) { Product entity = this.ownerProductCurator.getProductByIdUsingOwnerKey(ownerKey, productId); return entity != null ? this.prodCertCurator.getCertForProduct(entity) : null; } @Inject  DefaultProductServiceAdapter(OwnerProductCurator ownerProductCurator,
        ProductCertificateCurator prodCertCurator, ContentCurator contentCurator,
        UniqueIdGenerator idGenerator); @Override CertificateInfo getProductCertificate(String ownerKey, String productId); @Override @Transactional Collection<? extends ProductInfo> getProductsByIds(String ownerKey, Collection<String> ids);  }
@Test public void productCertificateExists() { Owner owner = TestUtil.createOwner("test_owner"); Product product = TestUtil.createProduct("test_product"); ProductCertificate cert = mock(ProductCertificate.class); when(opc.getProductByIdUsingOwnerKey(eq(owner.getKey()), eq(product.getId()))).thenReturn(product); doReturn(cert).when(pcc).findForProduct(eq(product)); CertificateInfo result = dpsa.getProductCertificate(owner.getKey(), product.getId()); verify(pcc, never()).create(eq(cert)); assertEquals(cert, result); }
@Test public void productCertificateNew() throws Exception { Owner owner = TestUtil.createOwner("test_owner"); Product product = TestUtil.createProduct("test_product"); ProductCertificate cert = mock(ProductCertificate.class); when(opc.getProductByIdUsingOwnerKey(eq(owner.getKey()), eq(product.getId()))).thenReturn(product); doAnswer(returnsFirstArg()).when(pcc).create(any(ProductCertificate.class)); doReturn(null).when(pcc).findForProduct(eq(product)); KeyPair kp = createKeyPair(); when(pki.generateNewKeyPair()).thenReturn(kp); when(pki.getPemEncoded(any(PrivateKey.class))).thenReturn("junk".getBytes()); CertificateInfo result = dpsa.getProductCertificate(owner.getKey(), product.getId()); assertNotNull(result); }