### Question:
SiteMapResourceChangeJobConsumer implements JobConsumer { @Override public JobResult process(final Job job) { @SuppressWarnings("unchecked") final Set<String> initialPaths = job.getProperty(PN_PATHS, Set.class); try (final ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver()) { for (final String path : initialPaths) { final Resource resource = ResourceUtils.getFirstExistingAncestorOnPath(resourceResolver, path); if (isAllowed(resource)) { cache.rebuild(resource.getPath()); } } } catch (final LoginException e) { logger.error("Unable to process job.", e); return JobResult.CANCEL; } return JobResult.OK; }  @Activate void activate(final SiteMapResourceChangeJobConsumerConfig config); @Override JobResult process(final Job job); static final String TOPIC; static final String PN_PATHS; }### Answer:
@SuppressWarnings("unchecked") @Test public void handleLoginException() throws LoginException { when(resourceResolverFactory.getServiceResourceResolver()).thenThrow(LoginException.class); assertEquals(JobConsumer.JobResult.CANCEL, model.process(job)); }
@Test public void process() { resource.setPrimaryType("per:X"); initialPaths.add(resource.getPath()); page.setPrimaryType("per:Page"); initialPaths.add(page.getPath()); parent.setPrimaryType("per:Y"); initialPaths.add(parent.getPath()); final Set<Object> rebuilt = new HashSet<>(); doAnswer(invocation -> { rebuilt.add(invocation.getArguments()[0]); return null; }).when(cache).rebuild(anyString()); assertEquals(JobConsumer.JobResult.OK, model.process(job)); assertTrue(rebuilt.contains(resource.getPath())); assertFalse(rebuilt.contains(page.getPath())); assertTrue(rebuilt.contains(parent.getPath())); }