@Test
public void checkNestedExceptionHandling() throws Exception {

    RuntimeException exceptionContainingUnknownPolicy =
            new RuntimeException
                    (new RuntimeException(
                            new RuntimeException(
                                    new RuntimeException(AutoScalePolicyException.unknownScalingPolicy("policyId", "Not found")))));
    Optional<AutoScalePolicyException> autoScalePolicyException = DefaultAppScaleManager.extractAutoScalePolicyException(exceptionContainingUnknownPolicy);
    AutoScalingPolicyTests.waitForCondition(() -> autoScalePolicyException.isPresent());
    Assertions.assertThat(autoScalePolicyException.isPresent()).isTrue();
    AutoScalingPolicyTests.waitForCondition(() -> autoScalePolicyException.get().getErrorCode() == AutoScalePolicyException.ErrorCode.UnknownScalingPolicy);
    Assertions.assertThat(autoScalePolicyException.get().getErrorCode()).isEqualTo(AutoScalePolicyException.ErrorCode.UnknownScalingPolicy);
    RuntimeException runtimeException = new RuntimeException(new RuntimeException(new Exception("Bad input")));
    Optional<AutoScalePolicyException> notAutoScalePolicyException = DefaultAppScaleManager.extractAutoScalePolicyException(runtimeException);
    AutoScalingPolicyTests.waitForCondition(() -> !notAutoScalePolicyException.isPresent());
    Assertions.assertThat(notAutoScalePolicyException.isPresent()).isFalse();
}