### Question:
SLAEnforcer { public int enforceSLAMin(int activeJobsCount, int acceptedJobsCount) { Preconditions.checkArgument(activeJobsCount >=0, "Invalid activeJobsCount " + activeJobsCount); Preconditions.checkArgument(acceptedJobsCount >=0, "Invalid acceptedJobsCount " + activeJobsCount); if(!sla.isPresent() || sla.get().getMin() == 0) { logger.debug("SLA min not set nothing to enforce"); return 0; } int jobsInActiveOrSubmittedState = activeJobsCount + acceptedJobsCount; if(jobsInActiveOrSubmittedState < sla.get().getMin()) { int jobsToLaunch = sla.get().getMin()-jobsInActiveOrSubmittedState; logger.info("Submit {} jobs per sla min of {}", jobsToLaunch, sla.get().getMin()); return jobsToLaunch; } logger.debug("SLA min already satisfied"); return 0; } SLAEnforcer(SLA sla); int enforceSLAMin(int activeJobsCount, int acceptedJobsCount); List<JobId> enforceSLAMax(List<JobInfo> list); boolean hasSLA();  }### Answer:
@Test public void slaMinInvalidArgTest() { int min = 2; int max = 0; try { SLA sla = new SLA(min,max, null, null); SLAEnforcer slaEnf = new SLAEnforcer(sla); slaEnf.enforceSLAMin(-1, 0); fail(); } catch(Exception e) {} }
@Test public void slaMinDefaultsTest() { SLA sla = new SLA(0,0, null, null); SLAEnforcer slaEnf = new SLAEnforcer(sla); assertEquals(0, slaEnf.enforceSLAMin(2, 0)); try { slaEnf = new SLAEnforcer(null); assertEquals(0, slaEnf.enforceSLAMin(2, 0)); } catch(Exception e) { fail(); } }
@Test public void slaMinTest() { int min = 2; int max = 10; SLA sla = new SLA(min,max, null, null); SLAEnforcer slaEnf = new SLAEnforcer(sla); assertEquals(0, slaEnf.enforceSLAMin(2, 0)); assertEquals(0, slaEnf.enforceSLAMin(1, 1)); assertEquals(1, slaEnf.enforceSLAMin(1, 0)); }