Skip to content

Commit 591e350

Browse files
author
Grzegorz Piwowarek
committed
Add additional tests
1 parent eff343b commit 591e350

4 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎immutables/src/main/java/com/baeldung/immutable/ValueObject.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
public class ValueObject {
44
public ValueObject() {
5+
6+
57
}
68
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

‎immutables/src/test/java/com/baeldung/immutable/ImmutablePersonTest.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

0 commit comments

Comments
 (0)