1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.lang3.builder;
19
20 import static org.hamcrest.MatcherAssert.assertThat;
21 import static org.hamcrest.Matchers.containsString;
22 import static org.hamcrest.Matchers.not;
23
24 import org.apache.commons.lang3.AbstractLangTest;
25 import org.junit.jupiter.api.Test;
26
27
28
29
30 public class ReflectionToStringBuilderExcludeWithAnnotationTest extends AbstractLangTest {
31
32 final class TestFixture {
33 @ToStringExclude
34 private final String excludedField = EXCLUDED_FIELD_VALUE;
35
36 @SuppressWarnings("unused")
37 private final String includedField = INCLUDED_FIELD_VALUE;
38 }
39
40 private static final String INCLUDED_FIELD_NAME = "includedField";
41
42 private static final String INCLUDED_FIELD_VALUE = "Hello World!";
43
44 private static final String EXCLUDED_FIELD_NAME = "excludedField";
45
46 private static final String EXCLUDED_FIELD_VALUE = "excluded field value";
47
48 @Test
49 public void test_toStringExclude() {
50 final String toString = ReflectionToStringBuilder.toString(new TestFixture());
51
52 assertThat(toString, not(containsString(EXCLUDED_FIELD_NAME)));
53 assertThat(toString, not(containsString(EXCLUDED_FIELD_VALUE)));
54 assertThat(toString, containsString(INCLUDED_FIELD_NAME));
55 assertThat(toString, containsString(INCLUDED_FIELD_VALUE));
56 }
57
58 }