### Question:
FSLeafQueue extends FSQueue { @Override public void updateDemand() { Resource maxRes = queueMgr.getMaxResources(getName()); demand = Resources.createResource(0); for (AppSchedulable sched : appScheds) { sched.updateDemand(); Resource toAdd = sched.getDemand(); if (LOG.isDebugEnabled()) { LOG.debug("Counting resource from " + sched.getName() + " " + toAdd + "; Total resource consumption for " + getName() + " now " + demand); } demand = Resources.add(demand, toAdd); if (Resources.greaterThanOrEqual(demand, maxRes)) { demand = maxRes; break; } } if (LOG.isDebugEnabled()) { LOG.debug("The updated demand for " + getName() + " is " + demand + "; the max is " + maxRes); } } FSLeafQueue(String name, QueueManager queueMgr, FairScheduler scheduler,
      FSParentQueue parent); void addApp(FSSchedulerApp app); void removeApp(FSSchedulerApp app); Collection<AppSchedulable> getAppSchedulables(); void setSchedulingMode(SchedulingMode mode); @Override void recomputeFairShares(); @Override Resource getDemand(); @Override Resource getResourceUsage(); @Override void updateDemand(); @Override Resource assignContainer(FSSchedulerNode node, boolean reserved); @Override Collection<FSQueue> getChildQueues(); @Override List<QueueUserACLInfo> getQueueUserAclInfo(UserGroupInformation user); long getLastTimeAtMinShare(); void setLastTimeAtMinShare(long lastTimeAtMinShare); long getLastTimeAtHalfFairShare(); void setLastTimeAtHalfFairShare(long lastTimeAtHalfFairShare);  }### Answer:
@Test public void testUpdateDemand() { AppSchedulable app = mock(AppSchedulable.class); Mockito.when(app.getDemand()).thenReturn(maxResource); schedulable.addAppSchedulable(app); schedulable.addAppSchedulable(app); schedulable.updateDemand(); assertTrue("Demand is greater than max allowed ", Resources.equals(schedulable.getDemand(), maxResource)); }