### Question:
UpgradePermissionProvider { public boolean permitCmAndStackUpgrade(Image currentImage, Image image, String versionKey, String buildNumberKey) { String currentVersion = getVersionFromImage(currentImage, versionKey); String newVersion = getVersionFromImage(image, versionKey); return versionsArePresent(currentVersion, newVersion) && permitCmAndStackUpgradeByComponentVersion(currentVersion, newVersion) || permitCmAndStackUpgradeByBuildNumber(currentImage, image, buildNumberKey, currentVersion, newVersion); }  boolean permitCmAndStackUpgrade(Image currentImage, Image image, String versionKey, String buildNumberKey); boolean permitExtensionUpgrade(String currentVersion, String newVersion);  }### Answer:
@Test public void testPermitUpgradeShouldReturnTrueWhenTheVersionsAreEqualAndTheBuildNumberIsGreater() { Image currentImage = createImage("7.2.1", "2000"); Image candidateImage = createImage("7.2.1", "2001"); when(componentBuildNumberComparator.compare(currentImage, candidateImage, BUILD_NUMBER_KEY)).thenReturn(true); boolean actual = underTest.permitCmAndStackUpgrade(currentImage, candidateImage, VERSION_KEY, BUILD_NUMBER_KEY); assertTrue(actual); verify(componentBuildNumberComparator).compare(currentImage, candidateImage, BUILD_NUMBER_KEY); }
@Test public void testPermitUpgradeShouldReturnFalseWhenTheVersionsAreEqualAndTheBuildNumberIsLower() { Image currentImage = createImage("7.2.1", "2002"); Image candidateImage = createImage("7.2.1", "2001"); when(componentBuildNumberComparator.compare(currentImage, candidateImage, BUILD_NUMBER_KEY)).thenReturn(false); boolean actual = underTest.permitCmAndStackUpgrade(currentImage, candidateImage, VERSION_KEY, BUILD_NUMBER_KEY); assertFalse(actual); verify(componentBuildNumberComparator).compare(currentImage, candidateImage, BUILD_NUMBER_KEY); }
@Test public void testPermitUpgradeShouldReturnTrueWhenTheCandidateCmVersionIsGreater() { Image currentImage = createImage("7.2.1", "2002"); Image candidateImage = createImage("7.2.2", "2001"); boolean actual = underTest.permitCmAndStackUpgrade(currentImage, candidateImage, VERSION_KEY, BUILD_NUMBER_KEY); assertTrue(actual); verifyNoInteractions(componentBuildNumberComparator); }
@Test public void testPermitUpgradeShouldReturnFalseWhenTheCmBuildNumberIsNotAvailable() { Image currentImage = createImage("7.2.1", "2002"); Image candidateImage = createImage("7.2.1", null); when(componentBuildNumberComparator.compare(currentImage, candidateImage, BUILD_NUMBER_KEY)).thenReturn(false); boolean actual = underTest.permitCmAndStackUpgrade(currentImage, candidateImage, VERSION_KEY, BUILD_NUMBER_KEY); assertFalse(actual); verify(componentBuildNumberComparator).compare(currentImage, candidateImage, BUILD_NUMBER_KEY); }