@Test
  public void testPreUpgradeCheckThrowsException() throws Exception {
    final CheckHelper helper = new CheckHelper();
    helper.clustersProvider = () -> clusters;
    helper.repositoryVersionDaoProvider = () -> repositoryVersionDao;

    Configuration configuration = EasyMock.createNiceMock(Configuration.class);
    List<UpgradeCheck> updateChecksRegistry = new ArrayList<>();

    EasyMock.expect(configuration.isUpgradePrecheckBypass()).andReturn(false);
    EasyMock.replay(configuration);
    updateChecksRegistry.add(m_mockCheck);

    // this will cause an exception
    Mockito.when(m_mockPerform.toString()).thenThrow(new RuntimeException());

    ClusterInformation clusterInformation = new ClusterInformation("cluster", false, null, null, null);
    UpgradeCheckRequest request = new UpgradeCheckRequest(clusterInformation, UpgradeType.ROLLING, m_repositoryVersion, null, null);

    helper.performChecks(request, updateChecksRegistry, configuration);

    Assert.assertEquals(UpgradeCheckStatus.FAIL, request.getResult(m_mockUpgradeCheckDescription));
  }
Check that throwing an exception still fails.
ambari-server/src/test/java/org/apache/ambari/server/state/CheckHelperTest.java