Add additional tests
This commit is contained in:
parent
eff343b596
commit
591e3507fb
|
@ -2,5 +2,7 @@ package com.baeldung.immutable;
|
|||
|
||||
public class ValueObject {
|
||||
public ValueObject() {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -17,6 +17,7 @@ public class ImmutablePersonTest {
|
|||
|
||||
assertThat(john)
|
||||
.isNotSameAs(john43);
|
||||
|
||||
assertThat(john.getAge())
|
||||
.isEqualTo(42);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue