24 lines
616 B
Java
Raw Normal View History

2016-07-30 10:50:47 +02:00
package com.baeldung.immutable;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class ImmutablePersonTest {
@Test
public void whenModifying_shouldCreateNewInstance() throws Exception {
final com.baeldung.immutable.ImmutablePerson john = com.baeldung.immutable.ImmutablePerson.builder()
.age(42)
.name("John")
.build();
final com.baeldung.immutable.ImmutablePerson john43 = john.withAge(43);
assertThat(john)
.isNotSameAs(john43);
2016-07-30 12:08:27 +02:00
2016-07-30 10:50:47 +02:00
assertThat(john.getAge())
.isEqualTo(42);
}
}