### Question:
EntitlementDrivenPackageLocationFilter { public Predicate<Image> filterImage(Image currentImage) { String accountId = ThreadBasedUserCrnProvider.getAccountId(); if (entitlementService.isInternalRepositoryForUpgradeAllowed(INTERNAL_ACTOR_CRN, accountId)) { LOGGER.debug("Skipping image filtering based on repository url"); return image -> true; } else { return image -> filters.stream().allMatch(filter -> filter.filterImage(image, currentImage)); } } EntitlementDrivenPackageLocationFilter(EntitlementService entitlementService, Set<PackageLocationFilter> filters); Predicate<Image> filterImage(Image currentImage);  }### Answer:
@Test public void testEnitlementEnabled() { PackageLocationFilter filter = mock(PackageLocationFilter.class); when(entitlementService.isInternalRepositoryForUpgradeAllowed(anyString(), anyString())).thenReturn(Boolean.TRUE); EntitlementDrivenPackageLocationFilter underTest = new EntitlementDrivenPackageLocationFilter(entitlementService, Set.of(filter)); Predicate<Image> imagePredicate = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.filterImage(mock(Image.class))); boolean result = imagePredicate.test(mock(Image.class)); assertTrue(result); verify(filter, never()).filterImage(any(Image.class), any(Image.class)); }
@Test public void testAcceptedImageMultipleFilters() { Set<PackageLocationFilter> filters = Set.of(createAcceptingFilter(), createAcceptingFilter(), createAcceptingFilter(), createAcceptingFilter()); EntitlementDrivenPackageLocationFilter underTest = new EntitlementDrivenPackageLocationFilter(entitlementService, filters); Predicate<Image> imagePredicate = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.filterImage(mock(Image.class))); boolean result = imagePredicate.test(mock(Image.class)); assertTrue(result); filters.forEach(filter -> verify(filter).filterImage(any(Image.class), any(Image.class))); }
@Test public void testRejectedImageMultipleFilters() { Set<PackageLocationFilter> filters = Set.of(createAcceptingFilter(), createAcceptingFilter(), createRejectingFilter(), createAcceptingFilter()); EntitlementDrivenPackageLocationFilter underTest = new EntitlementDrivenPackageLocationFilter(entitlementService, filters); Predicate<Image> imagePredicate = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.filterImage(mock(Image.class))); boolean result = imagePredicate.test(mock(Image.class)); assertFalse(result); }
@Test public void testRejectedImageMultipleRejectingFilters() { Set<PackageLocationFilter> filters = Set.of(createRejectingFilter(), createRejectingFilter(), createRejectingFilter()); EntitlementDrivenPackageLocationFilter underTest = new EntitlementDrivenPackageLocationFilter(entitlementService, filters); Predicate<Image> imagePredicate = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.filterImage(mock(Image.class))); boolean result = imagePredicate.test(mock(Image.class)); assertFalse(result); }