UnmappedGuestEntitlementCleanerJob implements AsyncJob { @Override public void execute(JobExecutionContext context) throws JobExecutionException { int total = entitler.revokeUnmappedGuestEntitlements(); String outcome; if (total > 0) { outcome = String.format("Reaped %d unmapped guest entitlements due to expiration.", total); log.info(outcome); } else { outcome = "No unmapped guest entitlements need reaping."; log.debug(outcome); } context.setJobResult(outcome); } @Inject  UnmappedGuestEntitlementCleanerJob(Entitler entitler); @Override void execute(JobExecutionContext context); static final String JOB_KEY; static final String JOB_NAME; static final String DEFAULT_SCHEDULE; }
@Test public void executeReapedSomeEntitlements() throws Exception { when(entitler.revokeUnmappedGuestEntitlements()).thenReturn(10); JobExecutionContext context = mock(JobExecutionContext.class); UnmappedGuestEntitlementCleanerJob job = this.createJobInstance(); ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class); job.execute(context); verify(context, times(1)).setJobResult(captor.capture()); Object result = captor.getValue(); assertEquals("Reaped 10 unmapped guest entitlements due to expiration.", result); }
@Test public void executeReapedNoEntitlements() throws Exception { when(entitler.revokeUnmappedGuestEntitlements()).thenReturn(0); JobExecutionContext context = mock(JobExecutionContext.class); UnmappedGuestEntitlementCleanerJob job = this.createJobInstance(); ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class); job.execute(context); verify(context, times(1)).setJobResult(captor.capture()); Object result = captor.getValue(); assertEquals("No unmapped guest entitlements need reaping.", result); }