JobStatisticsAPIImpl implements JobStatisticsAPI { @Override public Collection<JobBriefInfo> getJobsBriefInfo(final String ip) { List<String> jobNames = regCenter.getChildrenKeys("/"); List<JobBriefInfo> result = new ArrayList<>(jobNames.size()); for (String each : jobNames) { JobBriefInfo jobBriefInfo = getJobBriefInfoByJobNameAndIp(each, ip); if (null != jobBriefInfo) { result.add(jobBriefInfo); } } Collections.sort(result); return result; }  @Override int getJobsTotalCount(); @Override Collection<JobBriefInfo> getAllJobsBriefInfo(); @Override JobBriefInfo getJobBriefInfo(final String jobName); @Override Collection<JobBriefInfo> getJobsBriefInfo(final String ip);  }
@Test public void assertGetJobsBriefInfoByIp() { when(regCenter.getChildrenKeys("/")).thenReturn(Arrays.asList("test_job_1", "test_job_2", "test_job_3")); when(regCenter.isExisted("/test_job_1/servers/ip1")).thenReturn(true); when(regCenter.isExisted("/test_job_2/servers/ip1")).thenReturn(true); when(regCenter.get("/test_job_2/servers/ip1")).thenReturn("DISABLED"); when(regCenter.getChildrenKeys("/test_job_1/instances")).thenReturn(Collections.singletonList("ip1@-@defaultInstance")); int i = 0; for (JobBriefInfo each : jobStatisticsAPI.getJobsBriefInfo("ip1")) { assertThat(each.getJobName(), is("test_job_" + ++i)); if (i == 1) { assertThat(each.getInstanceCount(), is(1)); assertThat(each.getStatus(), is(JobBriefInfo.JobStatus.OK)); } else if (i == 2) { assertThat(each.getInstanceCount(), is(0)); assertThat(each.getStatus(), is(JobBriefInfo.JobStatus.DISABLED)); } } }