### Question:
JobWatcherUtil { static StateView computeState(Map<UUID, JobDefinition> jobs, Map<UUID, InstanceInfo> instances) { HashMap<UUID, UUID> instanceToJob = new HashMap<>(); HashMap<UUID, List<InstanceInfo>> jobInstances = new HashMap<>(); for (Map.Entry<UUID, InstanceInfo> e : instances.entrySet()) { YarnApplicationState state = YarnApplicationState.valueOf(e.getValue().status().getState().toString()); if (!isInstanceAlive(state)) { continue; } UUID jobId = e.getValue().metadata().jobDefinition(); UUID instanceId = e.getKey(); instanceToJob.put(instanceId, jobId); if (!jobInstances.containsKey(jobId)) { jobInstances.put(jobId, new ArrayList<>()); } jobInstances.get(jobId).add(e.getValue()); } jobs.keySet().stream().filter(x -> !jobInstances.containsKey(x)) .forEach(x -> jobInstances.put(x, Collections.emptyList())); return new StateView(jobs, instances, instanceToJob, jobInstances); } private  JobWatcherUtil();   }### Answer:
@Test public void testComputeState() { HashMap<UUID, JobDefinition> jobMap = new HashMap<>(); HashMap<UUID, InstanceInfo> instanceMap = new HashMap<>(); mockState1(jobMap, instanceMap); JobWatcherUtil.StateView v = JobWatcherUtil.computeState(jobMap, instanceMap); HashMap<UUID, List<InstanceInfo>> jobInstances = new HashMap<>(); HashMap<UUID, UUID> instanceToJob = new HashMap<>(); for (Map.Entry<UUID, InstanceInfo> e : instanceMap.entrySet()) { UUID jobId = e.getValue().metadata().jobDefinition(); instanceToJob.put(e.getKey(), jobId); List<InstanceInfo> li = jobInstances.getOrDefault(jobId, new ArrayList<>()); li.add(e.getValue()); jobInstances.put(jobId, li); } assertEquals(jobMap, v.jobs()); assertEquals(instanceMap, v.instances()); assertEquals(instanceToJob, v.instanceToJob()); assertEquals(jobInstances, v.jobInstances()); }