BAEL-4969: Improvement: Streams to Immutable Collections (#11026)
* add new module for java core 16 * format pom.xml
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.streams;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class StreamToImmutableUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenUsingStreamToList_thenReturnImmutableList() {
|
||||
|
||||
List<String> immutableList = Stream.of("a", "b", "c", "d")
|
||||
.toList();
|
||||
|
||||
Assertions.assertThrows(UnsupportedOperationException.class, () -> {
|
||||
immutableList.add("e");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user