### Question:
PreviousUpgradeCompleted extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); String errorMessage = null; UpgradeEntity upgradeInProgress = cluster.getUpgradeInProgress(); if (null != upgradeInProgress) { Direction direction = upgradeInProgress.getDirection(); String directionText = direction.getText(false); String prepositionText = direction.getPreposition(); errorMessage = MessageFormat.format(ERROR_MESSAGE, directionText, prepositionText, upgradeInProgress.getRepositoryVersion().getVersion(), directionText); } if (null != errorMessage) { LinkedHashSet<String> failedOn = new LinkedHashSet<>(); failedOn.add(cluster.getClusterName()); prerequisiteCheck.setFailedOn(failedOn); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(errorMessage); } } PreviousUpgradeCompleted(); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request); static final String ERROR_MESSAGE; }### Answer:
@Test public void testPerform() throws Exception { Mockito.when(cluster.getUpgradeInProgress()).thenReturn(null); PrerequisiteCheck check = new PrerequisiteCheck(null, null); puc.perform(check, checkRequest); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); UpgradeEntity upgradeInProgress = Mockito.mock(UpgradeEntity.class); Mockito.when(upgradeInProgress.getDirection()).thenReturn(Direction.UPGRADE); Mockito.when(upgradeInProgress.getClusterId()).thenReturn(1L); Mockito.when(upgradeInProgress.getRepositoryVersion()).thenReturn(toRepsitoryVersion); Mockito.when(cluster.getUpgradeInProgress()).thenReturn(upgradeInProgress); check = new PrerequisiteCheck(null, null); puc.perform(check, checkRequest); Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); }