@Test(expected = NotFoundException.class) public void testUpdateContentThrowsExceptionWhenOwnerDoesNotExist() { Content content = mock(Content.class); when(cc.find(any(String.class))).thenReturn(null); ocr.updateContent("owner", "someId", content); }
@Test public void testUpdateContent() { final String ownerId = "owner"; final String productId = "productId"; final String contentId = "10"; Owner owner = mock(Owner.class); Product product = mock(Product.class); Content content = mock(Content.class); when(product.getId()).thenReturn(productId); when(product.getOwner()).thenReturn(owner); when(content.getId()).thenReturn(contentId); when(content.getOwner()).thenReturn(owner); when(oc.lookupByKey(eq(ownerId))).thenReturn(owner); when(cc.lookupById(eq(owner), eq(contentId))).thenReturn(content); when(cc.createOrUpdate(eq(content))).thenReturn(content); when(productCurator.getProductsWithContent(eq(owner), eq(Arrays.asList(contentId)))) .thenReturn(Arrays.asList(product)); ocr.updateContent(ownerId, contentId, content); verify(cc).lookupById(eq(owner), eq(contentId)); verify(cc).createOrUpdate(eq(content)); verify(productCurator).getProductsWithContent(eq(owner), eq(Arrays.asList(contentId))); verify(poolManager).regenerateCertificatesOf(eq(owner), eq(productId), eq(true)); }
@Test(expected = NotFoundException.class) public void testUpdateContentThrowsExceptionWhenContentDoesNotExist() { Owner owner = mock(Owner.class); Content content = mock(Content.class); when(oc.lookupByKey(eq("owner"))).thenReturn(owner); when(cc.lookupById(eq(owner), any(String.class))).thenReturn(null); ocr.updateContent("owner", "someId", content); }