HealEntireOrgJob implements AsyncJob { @Inject public HealEntireOrgJob(Entitler entitler, EventSink eventSink, ConsumerCurator consumerCurator, OwnerCurator ownerCurator, I18n i18n) { this.entitler = Objects.requireNonNull(entitler); this.eventSink = Objects.requireNonNull(eventSink); this.consumerCurator = Objects.requireNonNull(consumerCurator); this.ownerCurator = Objects.requireNonNull(ownerCurator); this.i18n = Objects.requireNonNull(i18n); } @Inject  HealEntireOrgJob(Entitler entitler, EventSink eventSink, ConsumerCurator consumerCurator,
        OwnerCurator ownerCurator, I18n i18n); @Override void execute(JobExecutionContext context); static HealEntireOrgJobConfig createJobConfig(); String healSingleConsumer(Object... args); static final String JOB_KEY; static final String JOB_NAME; static final String OWNER_KEY; static final String ENTITLE_DATE_KEY; }
@Test public void testHealEntireOrgJob() throws JobExecutionException { Owner owner = this.createTestOwner(HealEntireOrgJob.OWNER_KEY, "log_level"); doReturn(owner).when(ownerCurator).getByKey(owner.getKey()); Consumer consumer1 = TestUtil.createConsumer(owner); Consumer consumer2 = TestUtil.createConsumer(owner); Map<String, Consumer> consumers = new HashMap<String, Consumer>() { { put(consumer1.getUuid(), consumer1); put(consumer2.getUuid(), consumer2); } }; doReturn(new EmptyCandlepinQuery<String>() { @Override public List<String> list() { return Arrays.asList(consumer1.getUuid(), consumer2.getUuid()); } }).when(ownerCurator).getConsumerUuids(owner); doAnswer(new Answer<Consumer>() { @Override public Consumer answer(InvocationOnMock invocation) throws Throwable { return consumers.get(invocation.getArguments()[0].toString()); } }).when(consumerCurator).getConsumer(anyString()); Date entitleDate = new Date(); JobConfig config = HealEntireOrgJob.createJobConfig().setOwner(owner).setEntitleDate(entitleDate); JobExecutionContext context = mock(JobExecutionContext.class); when(context.getJobArguments()).thenReturn(config.getJobArguments()); HealEntireOrgJob healEntireOrgJob = this.createJob(); ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class); healEntireOrgJob.execute(context); verify(context, times(1)).setJobResult(captor.capture()); Object result = captor.getValue(); StringBuilder expectedResult = new StringBuilder(); expectedResult.append("Successfully healed consumer with UUID: ").append(consumer1.getUuid()) .append("\n"); expectedResult.append("Successfully healed consumer with UUID: ").append(consumer2.getUuid()) .append("\n"); assertEquals(expectedResult.toString(), result.toString()); }