### Question:
CmAndStackVersionFilter { public Predicate<Image> filterCmAndStackVersion(Image currentImage, boolean lockComponents, Map<String, String> activatedParcels, Mutable<String> reason) { return candidateImage -> { updateReason(lockComponents, activatedParcels, reason); return isUpgradePermitted(currentImage, lockComponents, activatedParcels, candidateImage); }; }  Predicate<Image> filterCmAndStackVersion(Image currentImage, boolean lockComponents, Map<String, String> activatedParcels,
            Mutable<String> reason);  }### Answer:
@Test public void testFilterShouldReturnFalseWhenNotLockedAndStackPermitcheckIsFalse() { when(upgradePermissionProvider.permitCmAndStackUpgrade(currentImage, candidateImage, STACK_PACKAGE_KEY, CDH_BUILD_NUMBER_KEY)).thenReturn(Boolean.FALSE); when(upgradePermissionProvider.permitCmAndStackUpgrade(currentImage, candidateImage, CM_PACKAGE_KEY, CM_BUILD_NUMBER_KEY)).thenReturn(Boolean.TRUE); Predicate<Image> predicate = underTest.filterCmAndStackVersion(currentImage, false, activatedParcels, reason); boolean result = predicate.test(candidateImage); assertFalse(result); assertNotLockedCommon(); }
@Test public void testFilterShouldReturnFalseWhenNotLockedAndCMPermitcheckIsFalse() { lenient().when(upgradePermissionProvider.permitCmAndStackUpgrade(currentImage, candidateImage, STACK_PACKAGE_KEY, CDH_BUILD_NUMBER_KEY)) .thenReturn(Boolean.TRUE); when(upgradePermissionProvider.permitCmAndStackUpgrade(currentImage, candidateImage, CM_PACKAGE_KEY, CM_BUILD_NUMBER_KEY)).thenReturn(Boolean.FALSE); Predicate<Image> predicate = underTest.filterCmAndStackVersion(currentImage, false, activatedParcels, reason); boolean result = predicate.test(candidateImage); assertFalse(result); assertNotLockedCommon(); }
@Test public void testFilterShouldReturnFalseWhenNotLockedAndCMAndStackPermitcheckIsFalse() { lenient().when(upgradePermissionProvider.permitCmAndStackUpgrade(currentImage, candidateImage, STACK_PACKAGE_KEY, CDH_BUILD_NUMBER_KEY)) .thenReturn(Boolean.FALSE); when(upgradePermissionProvider.permitCmAndStackUpgrade(currentImage, candidateImage, CM_PACKAGE_KEY, CM_BUILD_NUMBER_KEY)).thenReturn(Boolean.FALSE); Predicate<Image> predicate = underTest.filterCmAndStackVersion(currentImage, false, activatedParcels, reason); boolean result = predicate.test(candidateImage); assertFalse(result); assertNotLockedCommon(); }
@Test public void testFilterShouldReturnTrueWhenNotLockedAndCMAndStackPermitcheckIsTrue() { when(upgradePermissionProvider.permitCmAndStackUpgrade(currentImage, candidateImage, STACK_PACKAGE_KEY, CDH_BUILD_NUMBER_KEY)).thenReturn(Boolean.TRUE); when(upgradePermissionProvider.permitCmAndStackUpgrade(currentImage, candidateImage, CM_PACKAGE_KEY, CM_BUILD_NUMBER_KEY)).thenReturn(Boolean.TRUE); Predicate<Image> predicate = underTest.filterCmAndStackVersion(currentImage, false, activatedParcels, reason); boolean result = predicate.test(candidateImage); assertTrue(result); assertNotLockedCommon(); }