File tree Expand file tree Collapse file tree
main/java/com/baeldung/lombok/getter
test/java/com/baeldung/lombok/getter Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung .lombok .getter ;
2+
3+
4+ import lombok .Getter ;
5+
6+ /**
7+ * Related Article Sections:
8+ * 4. Using @Getter on a Boolean Field
9+ *
10+ */
11+ public class GetterBoolean {
12+
13+ @ Getter
14+ private Boolean running = true ;
15+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .lombok .getter ;
2+
3+
4+ import lombok .Getter ;
5+
6+ /**
7+ * Related Article Sections:
8+ * 3. Using @Getter on a boolean Field
9+ *
10+ */
11+ public class GetterBooleanPrimitive {
12+
13+ @ Getter
14+ private boolean running ;
15+
16+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .lombok .getter ;
2+
3+
4+ import lombok .Getter ;
5+
6+ /**
7+ * Related Article Sections:
8+ * 3.2. Two boolean Fields With the Same Accessor Name
9+ *
10+ */
11+ public class GetterBooleanPrimitiveSameAccessor {
12+
13+ @ Getter
14+ boolean running = true ;
15+
16+ @ Getter
17+ boolean isRunning = false ;
18+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .lombok .getter ;
2+
3+ import lombok .Getter ;
4+
5+ /**
6+ * Related Article Sections:
7+ * 3.1. A boolean Field Having the Same Name With Its Accessor
8+ *
9+ */
10+ public class GetterBooleanSameAccessor {
11+ @ Getter
12+ private boolean isRunning = true ;
13+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .lombok .getter ;
2+
3+
4+ import lombok .Getter ;
5+
6+ /**
7+ * Related Article Sections:
8+ * 4. Using @Getter on a Boolean Field
9+ *
10+ */
11+ public class GetterBooleanType {
12+
13+ @ Getter
14+ private Boolean running = true ;
15+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .lombok .getter ;
2+
3+ import static org .junit .Assert .assertFalse ;
4+ import static org .junit .Assert .assertTrue ;
5+
6+ import org .junit .Test ;
7+
8+ public class GetterBooleanUnitTest {
9+
10+ @ Test
11+ public void whenBasicBooleanField_thenMethodNamePrefixedWithIsFollowedByFieldName () {
12+ GetterBooleanPrimitive lombokExamples = new GetterBooleanPrimitive ();
13+ assertFalse (lombokExamples .isRunning ());
14+ }
15+
16+ @ Test
17+ public void whenBooleanFieldPrefixedWithIs_thenMethodNameIsSameAsFieldName () {
18+ GetterBooleanSameAccessor lombokExamples = new GetterBooleanSameAccessor ();
19+ assertTrue (lombokExamples .isRunning ());
20+ }
21+
22+ @ Test
23+ public void whenTwoBooleanFieldsCauseNamingConflict_thenLombokMapsToFirstDeclaredField () {
24+ GetterBooleanPrimitiveSameAccessor lombokExamples = new GetterBooleanPrimitiveSameAccessor ();
25+ assertTrue (lombokExamples .isRunning () == lombokExamples .running );
26+ assertFalse (lombokExamples .isRunning () == lombokExamples .isRunning );
27+ }
28+
29+ @ Test
30+ public void whenFieldOfBooleanType_thenLombokPrefixesMethodWithGetInsteadOfIs () {
31+ GetterBooleanType lombokExamples = new GetterBooleanType ();
32+ assertTrue (lombokExamples .getRunning ());
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments