HarvestBandwidthManagerImpl implements HarvestBandwidthManager { @Override public void saveOrUpdate(BandwidthRestriction bandwidthRestriction) { boolean isNew = bandwidthRestriction.getOid() == null; harvestCoordinatorDao.saveOrUpdate(bandwidthRestriction); if (isNew) { auditor.audit(BandwidthRestriction.class.getName(), bandwidthRestriction.getOid(), Auditor.ACTION_NEW_BANDWIDTH_RESTRICTION, "New bandwidth restriction: " + bandwidthRestriction.toString()); } else { auditor.audit(BandwidthRestriction.class.getName(), bandwidthRestriction.getOid(), Auditor.ACTION_CHANGE_BANDWIDTH_RESTRICTION, "Bandwidth setting changed to: " + bandwidthRestriction.toString()); } }  @Override void sendBandWidthRestrictions(); @Override HashMap<Long, TargetInstance> calculateBandwidthAllocation(TargetInstance aTargetInstance); @Override HashMap<Long, TargetInstance> calculateBandwidthAllocation(); @Override long getCurrentGlobalMaxBandwidth(); @Override boolean isMiniumBandwidthAvailable(QueuedTargetInstanceDTO aTargetInstance); @Override boolean isMiniumBandwidthAvailable(TargetInstance aTargetInstance); @Override synchronized void checkForBandwidthTransition(); @Override boolean isHarvestOptimizationAllowed(); @Override BandwidthRestriction getBandwidthRestriction(Long oid); @Override void saveOrUpdate(BandwidthRestriction bandwidthRestriction); @Override void delete(BandwidthRestriction bandwidthRestriction); @Override BandwidthRestriction getBandwidthRestriction(String aDay, Date aTime); @Override HashMap<String, List<BandwidthRestriction>> getBandwidthRestrictions(); @Override int getMinimumBandwidth(); @Override void setMinimumBandwidth(int minimumBandwidth); @Override int getMaxBandwidthPercent(); @Override void setMaxBandwidthPercent(int maxBandwidthPercent); void setHarvestCoordinatorDao(HarvestCoordinatorDAO harvestCoordinatorDao); void setHarvestAgentManager(HarvestAgentManager harvestAgentManager); void setTargetInstanceDao(TargetInstanceDAO targetInstanceDao); void setAuditor(Auditor auditor); void setBandwidthCalculator(BandwidthCalculator bandwidthCalculator);  }
@Test public void testSaveOrUpdateNew() throws Exception { BandwidthRestriction mockBandwidthRestriction = mock(BandwidthRestriction.class); when(mockBandwidthRestriction.getOid()).thenReturn(null); underTest.saveOrUpdate(mockBandwidthRestriction); verify(mockHarvestCoordinatorDao).saveOrUpdate(mockBandwidthRestriction); verify(mockAuditor).audit(anyString(), eq((Long)null), eq(Auditor.ACTION_NEW_BANDWIDTH_RESTRICTION), anyString()); }
@Test public void testSaveOrUpdateNotNew() throws Exception { BandwidthRestriction mockBandwidthRestriction = mock(BandwidthRestriction.class); long oid = 123L; when(mockBandwidthRestriction.getOid()).thenReturn(oid); underTest.saveOrUpdate(mockBandwidthRestriction); verify(mockHarvestCoordinatorDao).saveOrUpdate(mockBandwidthRestriction); verify(mockAuditor).audit(anyString(), eq(oid), eq(Auditor.ACTION_CHANGE_BANDWIDTH_RESTRICTION), anyString()); }