Source:
public void testDeleteExcessEntitlements() throws EntitlementRefusedException { Consumer consumer = TestUtil.createConsumer(o); Subscription sub = TestUtil.createSubscription(o, product); sub.setId("testing-subid"); pool.setSourceSubscription(new SourceSubscription(sub.getId(), "master")); Pool derivedPool = TestUtil.createPool(o, product, 1); derivedPool.setAttribute(Pool.DERIVED_POOL_ATTRIBUTE, "true"); derivedPool.setSourceSubscription(new SourceSubscription(sub.getId(), "der")); derivedPool.setConsumed(3L); derivedPool.setId("derivedPool"); Entitlement masterEnt = new Entitlement(pool, consumer, 5); Entitlement derivedEnt = new Entitlement(derivedPool, consumer, 1); derivedEnt.setId("1"); Set<Entitlement> ents = new HashSet<Entitlement>(); ents.add(derivedEnt); derivedPool.setEntitlements(ents); assertEquals(3, derivedPool.getConsumed().intValue()); assertEquals(1, derivedPool.getEntitlements().size()); when(mockPoolCurator.lockAndLoad(anyCollection())).thenReturn(Arrays.asList(pool)); when(mockPoolCurator.lookupOversubscribedBySubscriptionIds(anyMap())).thenReturn( Arrays.asList(derivedPool)); when(mockPoolCurator.retrieveFreeEntitlementsOfPools(anyListOf(Pool.class), eq(true))).thenReturn( Arrays.asList(derivedEnt)); when(mockPoolCurator.lockAndLoad(eq(derivedPool))).thenReturn(derivedPool); pool.setId("masterpool"); manager.adjustEntitlementQuantity(consumer, masterEnt, 3); Class<List<Entitlement>> listClass = (Class<List<Entitlement>>) (Class) ArrayList.class; ArgumentCaptor<List<Entitlement>> arg = ArgumentCaptor.forClass(listClass); verify(entitlementCurator).batchDelete(arg.capture()); List<Entitlement> entsDeleted = arg.getValue(); assertTrue(entsDeleted.contains(derivedEnt)); assertEquals(2, derivedPool.getConsumed().intValue()); assertEquals(0, derivedPool.getEntitlements().size()); }

Target:
public void testDeleteExcessEntitlements() throws EntitlementRefusedException { Consumer consumer = TestUtil.createConsumer(o); Subscription sub = TestUtil.createSubscription(o, product); sub.setId("testing-subid"); pool.setSourceSubscription(new SourceSubscription(sub.getId(), "master")); Pool derivedPool = TestUtil.createPool(o, product, 1); derivedPool.setAttribute(Pool.DERIVED_POOL_ATTRIBUTE, "true"); derivedPool.setSourceSubscription(new SourceSubscription(sub.getId(), "der")); derivedPool.setConsumed(3L); derivedPool.setId("derivedPool"); Entitlement masterEnt = new Entitlement(pool, consumer, 5); Entitlement derivedEnt = new Entitlement(derivedPool, consumer, 1); derivedEnt.setId("1"); Set<Entitlement> ents = new HashSet<Entitlement>(); ents.add(derivedEnt); derivedPool.setEntitlements(ents); assertEquals(3, derivedPool.getConsumed().intValue()); assertEquals(1, derivedPool.getEntitlements().size()); when(mockPoolCurator.lockAndLoad(anyCollection())).thenReturn(Arrays.asList(pool)); when(mockPoolCurator.lookupOversubscribedBySubscriptionIds(anyMap())).thenReturn( Arrays.asList(derivedPool)); when(mockPoolCurator.retrieveFreeEntitlementsOfPools(anyListOf(Pool.class), eq(true))).thenReturn( Arrays.asList(derivedEnt)); when(mockPoolCurator.lockAndLoad(eq(derivedPool))).thenReturn(derivedPool); pool.setId("masterpool"); manager.adjustEntitlementQuantity(consumer, masterEnt, 3); Class<List<Entitlement>> listClass = (Class<List<Entitlement>>) (Class) ArrayList.class; ArgumentCaptor<List<Entitlement>> arg = ArgumentCaptor.forClass(listClass); verify(entitlementCurator).batchDelete(arg.capture()); List<Entitlement> entsDeleted = arg.getValue(); assertThat(entsDeleted, hasItem(derivedEnt)); assertEquals(2, derivedPool.getConsumed().intValue()); assertEquals(0, derivedPool.getEntitlements().size()); }