Add remaining examples
This commit is contained in:
parent
7b1c77c6bc
commit
eef41ec028
|
@ -0,0 +1,14 @@
|
|||
package com.baeldung.immutable.default_;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
@Value.Immutable(prehash = true)
|
||||
public abstract class Person {
|
||||
|
||||
abstract String getName();
|
||||
|
||||
@Value.Default
|
||||
Integer getAge() {
|
||||
return 42;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.baeldung.immutable.parameter;
|
||||
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
@Value.Immutable
|
||||
public abstract class Person {
|
||||
|
||||
@Value.Parameter
|
||||
abstract String getName();
|
||||
|
||||
@Value.Parameter
|
||||
abstract Integer getAge();
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.baeldung.immutable.prehash;
|
||||
|
||||
import org.immutables.value.Value;
|
||||
|
||||
@Value.Immutable(prehash = true)
|
||||
public abstract class Person {
|
||||
abstract String getName();
|
||||
abstract Integer getAge();
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.immutable.default_;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ImmutablePersonDefaultTest {
|
||||
|
||||
@Test
|
||||
public void whenInstantiating_shouldUseDefaultValue() throws Exception {
|
||||
|
||||
final com.baeldung.immutable.default_.ImmutablePerson john = com.baeldung.immutable.default_.ImmutablePerson.builder().name("John").build();
|
||||
|
||||
assertThat(john.getAge()).isEqualTo(42);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue