From 591e3507fb2f5ffa2019a0e805729599696d6911 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sat, 30 Jul 2016 12:08:27 +0200 Subject: [PATCH] Add additional tests --- .../com/baeldung/immutable/ValueObject.java | 2 ++ .../baeldung/immutable/auxiliary/Person.java | 13 ++++++++ .../immutable/ImmutablePersonTest.java | 1 + .../ImmutablePersonAuxiliaryTest.java | 33 +++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 immutables/src/main/java/com/baeldung/immutable/auxiliary/Person.java create mode 100644 immutables/src/test/java/com/baeldung/immutable/auxiliary/ImmutablePersonAuxiliaryTest.java diff --git a/immutables/src/main/java/com/baeldung/immutable/ValueObject.java b/immutables/src/main/java/com/baeldung/immutable/ValueObject.java index b598a9d12d..475c6bf7b1 100644 --- a/immutables/src/main/java/com/baeldung/immutable/ValueObject.java +++ b/immutables/src/main/java/com/baeldung/immutable/ValueObject.java @@ -2,5 +2,7 @@ package com.baeldung.immutable; public class ValueObject { public ValueObject() { + + } } diff --git a/immutables/src/main/java/com/baeldung/immutable/auxiliary/Person.java b/immutables/src/main/java/com/baeldung/immutable/auxiliary/Person.java new file mode 100644 index 0000000000..78fe28c50c --- /dev/null +++ b/immutables/src/main/java/com/baeldung/immutable/auxiliary/Person.java @@ -0,0 +1,13 @@ +package com.baeldung.immutable.auxiliary; + + +import org.immutables.value.Value; + +@Value.Immutable +public abstract class Person { + abstract String getName(); + abstract Integer getAge(); + + @Value.Auxiliary + abstract String getAuxiliaryField(); +} \ No newline at end of file diff --git a/immutables/src/test/java/com/baeldung/immutable/ImmutablePersonTest.java b/immutables/src/test/java/com/baeldung/immutable/ImmutablePersonTest.java index 8c53569836..aabdb4300a 100644 --- a/immutables/src/test/java/com/baeldung/immutable/ImmutablePersonTest.java +++ b/immutables/src/test/java/com/baeldung/immutable/ImmutablePersonTest.java @@ -17,6 +17,7 @@ public class ImmutablePersonTest { assertThat(john) .isNotSameAs(john43); + assertThat(john.getAge()) .isEqualTo(42); } diff --git a/immutables/src/test/java/com/baeldung/immutable/auxiliary/ImmutablePersonAuxiliaryTest.java b/immutables/src/test/java/com/baeldung/immutable/auxiliary/ImmutablePersonAuxiliaryTest.java new file mode 100644 index 0000000000..a81eeb3a3a --- /dev/null +++ b/immutables/src/test/java/com/baeldung/immutable/auxiliary/ImmutablePersonAuxiliaryTest.java @@ -0,0 +1,33 @@ +package com.baeldung.immutable.auxiliary; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ImmutablePersonAuxiliaryTest { + + @Test + public void whenComparing_shouldIgnore() throws Exception { + final com.baeldung.immutable.auxiliary.ImmutablePerson john1 = com.baeldung.immutable.auxiliary.ImmutablePerson.builder() + .name("John") + .age(42) + .auxiliaryField("Value1") + .build(); + + final com.baeldung.immutable.auxiliary.ImmutablePerson john2 = com.baeldung.immutable.auxiliary.ImmutablePerson.builder() + .name("John") + .age(42) + .auxiliaryField("Value2") + .build(); + + + assertThat(john1.equals(john2)) + .isTrue(); + + assertThat(john1.toString()) + .isEqualTo(john2.toString()); + + assertThat(john1.hashCode()) + .isEqualTo(john2.hashCode()); + } +} \ No newline at end of file