|
| 1 | +/* |
| 2 | + * Copyright 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 | + |
| 16 | +package software.amazon.awssdk.core.interceptor; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | +import org.junit.Test; |
| 20 | + |
| 21 | +public class ExecutionAttributesTest { |
| 22 | + private static final ExecutionAttribute<String> ATTR_1 = new ExecutionAttribute<>("Attr1"); |
| 23 | + private static final ExecutionAttribute<String> ATTR_2 = new ExecutionAttribute<>("Attr2"); |
| 24 | + |
| 25 | + @Test |
| 26 | + public void equals_identity_returnsTrue() { |
| 27 | + ExecutionAttributes executionAttributes = ExecutionAttributes.builder() |
| 28 | + .put(ATTR_1, "hello") |
| 29 | + .put(ATTR_2, "world") |
| 30 | + .build(); |
| 31 | + |
| 32 | + assertThat(executionAttributes.equals(executionAttributes)).isTrue(); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void equals_sameAttributes_returnsTrue() { |
| 37 | + ExecutionAttributes executionAttributes1 = ExecutionAttributes.builder() |
| 38 | + .put(ATTR_1, "hello") |
| 39 | + .put(ATTR_2, "world") |
| 40 | + .build(); |
| 41 | + |
| 42 | + ExecutionAttributes executionAttributes2 = ExecutionAttributes.builder() |
| 43 | + .put(ATTR_1, "hello") |
| 44 | + .put(ATTR_2, "world") |
| 45 | + .build(); |
| 46 | + |
| 47 | + assertThat(executionAttributes1).isEqualTo(executionAttributes2); |
| 48 | + assertThat(executionAttributes2).isEqualTo(executionAttributes1); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void equals_differentAttributes_returnsFalse() { |
| 53 | + ExecutionAttributes executionAttributes1 = ExecutionAttributes.builder() |
| 54 | + .put(ATTR_1, "HELLO") |
| 55 | + .put(ATTR_2, "WORLD") |
| 56 | + .build(); |
| 57 | + |
| 58 | + ExecutionAttributes executionAttributes2 = ExecutionAttributes.builder() |
| 59 | + .put(ATTR_1, "hello") |
| 60 | + .put(ATTR_2, "world") |
| 61 | + .build(); |
| 62 | + |
| 63 | + assertThat(executionAttributes1).isNotEqualTo(executionAttributes2); |
| 64 | + assertThat(executionAttributes2).isNotEqualTo(executionAttributes1); |
| 65 | + } |
| 66 | + |
| 67 | + |
| 68 | + @Test |
| 69 | + public void hashCode_objectsEqual_valuesEqual() { |
| 70 | + ExecutionAttributes executionAttributes1 = ExecutionAttributes.builder() |
| 71 | + .put(ATTR_1, "hello") |
| 72 | + .put(ATTR_2, "world") |
| 73 | + .build(); |
| 74 | + |
| 75 | + ExecutionAttributes executionAttributes2 = ExecutionAttributes.builder() |
| 76 | + .put(ATTR_1, "hello") |
| 77 | + .put(ATTR_2, "world") |
| 78 | + .build(); |
| 79 | + |
| 80 | + assertThat(executionAttributes1.hashCode()).isEqualTo(executionAttributes2.hashCode()); |
| 81 | + } |
| 82 | +} |
0 commit comments