Add first test

This commit is contained in:
Grzegorz Piwowarek 2016-07-30 10:50:47 +02:00
parent ff84127f47
commit eff343b596
3 changed files with 31 additions and 3 deletions

View File

@ -1,5 +1,9 @@
package com.baeldung.immutable;
public class Address {
import org.immutables.value.Value;
@Value.Immutable
public interface Address {
String getStreetName();
Integer getNumber();
}

View File

@ -3,6 +3,7 @@ package com.baeldung.immutable;
import org.immutables.value.Value;
@Value.Immutable
public class Person {
private String name;
public abstract class Person {
abstract String getName();
abstract Integer getAge();
}

View File

@ -0,0 +1,23 @@
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);
assertThat(john.getAge())
.isEqualTo(42);
}
}