|
| 1 | +/* |
| 2 | +* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | +* |
| 4 | +* Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | +* You may not use this file except in compliance with the License. |
| 6 | +* A copy of the License is located at |
| 7 | +* |
| 8 | +* http://aws.amazon.com/apache2.0 |
| 9 | +* |
| 10 | +* or in the "license" file accompanying this file. This file is distributed |
| 11 | +* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | +* express or implied. See the License for the specific language governing |
| 13 | +* permissions and limitations under the License. |
| 14 | +*/ |
| 15 | +package software.amazon.cloudformation.exceptions; |
| 16 | + |
| 17 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
| 18 | +import org.junit.jupiter.api.Assertions; |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | +import software.amazon.cloudformation.proxy.HandlerErrorCode; |
| 21 | + |
| 22 | +public class CfnUnsupportedTargetExceptionTests { |
| 23 | + private static final String HOOK_TYPE = "AWS::Hook::Type"; |
| 24 | + private static final String UNSUPPORTED_TYPE = "AWS::Service::Resource"; |
| 25 | + private static final String STATUS = "unsupported target"; |
| 26 | + private static final String ERROR_MESSAGE = "something wrong"; |
| 27 | + |
| 28 | + @Test |
| 29 | + public void cfnUnsupportedTargetException_isBaseHandlerException() { |
| 30 | + assertThatExceptionOfType(BaseHandlerException.class).isThrownBy(() -> { |
| 31 | + throw new CfnUnsupportedTargetException(HOOK_TYPE, UNSUPPORTED_TYPE, new RuntimeException()); |
| 32 | + }).withCauseInstanceOf(RuntimeException.class).withMessageContaining(HOOK_TYPE).withMessageContaining(UNSUPPORTED_TYPE) |
| 33 | + .withMessageContaining(STATUS); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void cfnUnsupportedTargetException_singleArgsConstructorHasNoMessage() { |
| 38 | + assertThatExceptionOfType(CfnUnsupportedTargetException.class).isThrownBy(() -> { |
| 39 | + throw new CfnUnsupportedTargetException(new RuntimeException()); |
| 40 | + }).withCauseInstanceOf(RuntimeException.class).withMessage(null); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void cfnUnsupportedTargetException_noCauseGiven() { |
| 45 | + assertThatExceptionOfType(CfnUnsupportedTargetException.class).isThrownBy(() -> { |
| 46 | + throw new CfnUnsupportedTargetException(HOOK_TYPE, UNSUPPORTED_TYPE); |
| 47 | + }).withNoCause().withMessageContaining(HOOK_TYPE).withMessageContaining(UNSUPPORTED_TYPE).withMessageContaining(STATUS); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void cfnUnsupportedTargetException_errorCodeIsAppropriate() { |
| 52 | + assertThatExceptionOfType(CfnUnsupportedTargetException.class).isThrownBy(() -> { |
| 53 | + throw new CfnUnsupportedTargetException(new RuntimeException()); |
| 54 | + }).satisfies(exception -> Assertions.assertEquals(HandlerErrorCode.UnsupportedTarget, exception.getErrorCode())); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void cfnUnsupportedTargetException_errorMessage() { |
| 59 | + assertThatExceptionOfType(CfnUnsupportedTargetException.class).isThrownBy(() -> { |
| 60 | + throw new CfnUnsupportedTargetException(new RuntimeException(ERROR_MESSAGE)); |
| 61 | + }).satisfies(exception -> Assertions.assertEquals(ERROR_MESSAGE, exception.getMessage())); |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments