|
16 | 16 |
|
17 | 17 | package org.springframework.boot.web.servlet.error;
|
18 | 18 |
|
19 |
| -import static org.assertj.core.api.Assertions.assertThat; |
20 |
| - |
21 | 19 | import java.util.EnumSet;
|
22 |
| -import java.util.Set; |
23 | 20 |
|
24 | 21 | import org.junit.jupiter.api.Test;
|
| 22 | + |
25 | 23 | import org.springframework.boot.web.error.ErrorAttributeOptions;
|
26 | 24 | import org.springframework.boot.web.error.ErrorAttributeOptions.Include;
|
27 | 25 |
|
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
| 27 | + |
28 | 28 | /**
|
29 |
| - * Tests for {@link ErrorAttributesOptions}. |
| 29 | + * Tests for {@link ErrorAttributeOptions}. |
30 | 30 | *
|
31 | 31 | * @author Wanderlei Souza
|
| 32 | + * @author Stephane Nicoll |
32 | 33 | */
|
33 | 34 | class ErrorAttributesOptionsTests {
|
34 | 35 |
|
35 | 36 | @Test
|
36 |
| - void excludingFromEmptySetWithoutErrors() { |
37 |
| - Set<Include> includes = EnumSet.noneOf(Include.class); |
38 |
| - ErrorAttributeOptions errorAttributeOptions = ErrorAttributeOptions.of(includes); |
39 |
| - errorAttributeOptions = errorAttributeOptions.excluding(Include.EXCEPTION); |
40 |
| - assertThat(errorAttributeOptions.getIncludes().isEmpty()); |
| 37 | + void includingFromEmptyAttributesReturnAddedEntry() { |
| 38 | + ErrorAttributeOptions options = ErrorAttributeOptions.of(EnumSet.noneOf(Include.class)); |
| 39 | + assertThat(options.including(Include.EXCEPTION).getIncludes()).containsOnly(Include.EXCEPTION); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void includingFromMatchingAttributesDoesNotModifyOptions() { |
| 44 | + ErrorAttributeOptions options = ErrorAttributeOptions.of(EnumSet.of(Include.EXCEPTION, Include.STACK_TRACE)); |
| 45 | + assertThat(options.including(Include.EXCEPTION).getIncludes()).containsOnly(Include.EXCEPTION, |
| 46 | + Include.STACK_TRACE); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void excludingFromEmptyAttributesReturnEmptyList() { |
| 51 | + ErrorAttributeOptions options = ErrorAttributeOptions.of(EnumSet.noneOf(Include.class)); |
| 52 | + assertThat(options.excluding(Include.EXCEPTION).getIncludes()).isEmpty(); |
41 | 53 | }
|
42 |
| - |
| 54 | + |
43 | 55 | @Test
|
44 |
| - void includingInEmptySetWithoutErrors() { |
45 |
| - Set<Include> includes = EnumSet.noneOf(Include.class); |
46 |
| - ErrorAttributeOptions errorAttributeOptions = ErrorAttributeOptions.of(includes); |
47 |
| - errorAttributeOptions = errorAttributeOptions.including(Include.EXCEPTION); |
48 |
| - assertThat(errorAttributeOptions.getIncludes().isEmpty()); |
| 56 | + void excludingFromMatchingAttributesRemoveMatch() { |
| 57 | + ErrorAttributeOptions options = ErrorAttributeOptions.of(EnumSet.of(Include.EXCEPTION, Include.STACK_TRACE)); |
| 58 | + assertThat(options.excluding(Include.EXCEPTION).getIncludes()).containsOnly(Include.STACK_TRACE); |
49 | 59 | }
|
50 | 60 |
|
51 | 61 | }
|
0 commit comments