File tree Expand file tree Collapse file tree
main/java/com/baeldung/immutable
test/java/com/baeldung/immutable Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33public class ValueObject {
44 public ValueObject () {
5+
6+
57 }
68}
Original file line number Diff line number Diff line change 1+ package com .baeldung .immutable .auxiliary ;
2+
3+
4+ import org .immutables .value .Value ;
5+
6+ @ Value .Immutable
7+ public abstract class Person {
8+ abstract String getName ();
9+ abstract Integer getAge ();
10+
11+ @ Value .Auxiliary
12+ abstract String getAuxiliaryField ();
13+ }
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ public void whenModifying_shouldCreateNewInstance() throws Exception {
1717
1818 assertThat (john )
1919 .isNotSameAs (john43 );
20+
2021 assertThat (john .getAge ())
2122 .isEqualTo (42 );
2223 }
Original file line number Diff line number Diff line change 1+ package com .baeldung .immutable .auxiliary ;
2+
3+ import org .junit .Test ;
4+
5+ import static org .assertj .core .api .Assertions .assertThat ;
6+
7+ public class ImmutablePersonAuxiliaryTest {
8+
9+ @ Test
10+ public void whenComparing_shouldIgnore () throws Exception {
11+ final com .baeldung .immutable .auxiliary .ImmutablePerson john1 = com .baeldung .immutable .auxiliary .ImmutablePerson .builder ()
12+ .name ("John" )
13+ .age (42 )
14+ .auxiliaryField ("Value1" )
15+ .build ();
16+
17+ final com .baeldung .immutable .auxiliary .ImmutablePerson john2 = com .baeldung .immutable .auxiliary .ImmutablePerson .builder ()
18+ .name ("John" )
19+ .age (42 )
20+ .auxiliaryField ("Value2" )
21+ .build ();
22+
23+
24+ assertThat (john1 .equals (john2 ))
25+ .isTrue ();
26+
27+ assertThat (john1 .toString ())
28+ .isEqualTo (john2 .toString ());
29+
30+ assertThat (john1 .hashCode ())
31+ .isEqualTo (john2 .hashCode ());
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments