BAEL-7128: Optional as a Record Parameter in Java (#15114)
* record class and test * renaming test
This commit is contained in:
parent
4c06d8e9f9
commit
6f618f5cf9
|
@ -0,0 +1,6 @@
|
||||||
|
package com.baeldung.optionalsasparameterrecords;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public record Product(String name, double price, Optional<String> description) {
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.baeldung.optionalsasparameterrecords;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class OptionalAsRecordParameterUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenRecordCreationWithOptional_thenCreateItProperly() {
|
||||||
|
var emptyDescriptionProduct = new Product("television", 1699.99, Optional.empty());
|
||||||
|
Assertions.assertEquals("television", emptyDescriptionProduct.name());
|
||||||
|
Assertions.assertEquals(1699.99, emptyDescriptionProduct.price());
|
||||||
|
Assertions.assertNull(emptyDescriptionProduct.description().orElse(null));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue