From b5f816ae2d2d1ff71f01b64f6c215a75ff60e3e3 Mon Sep 17 00:00:00 2001 From: pivovarit Date: Mon, 8 May 2017 19:45:28 +0200 Subject: [PATCH] DoubleBraceTest refactor --- .../baeldung/java/doublebrace/DoubleBraceTest.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core-java/src/test/java/com/baeldung/java/doublebrace/DoubleBraceTest.java b/core-java/src/test/java/com/baeldung/java/doublebrace/DoubleBraceTest.java index 77d94f6544..531aa8970d 100644 --- a/core-java/src/test/java/com/baeldung/java/doublebrace/DoubleBraceTest.java +++ b/core-java/src/test/java/com/baeldung/java/doublebrace/DoubleBraceTest.java @@ -1,18 +1,21 @@ package com.baeldung.java.doublebrace; +import org.junit.Test; + import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; + +import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toSet; import static org.junit.Assert.assertTrue; -import org.junit.Test; public class DoubleBraceTest { @Test public void whenInitializeSetWithoutDoubleBraces_containsElements() { - final Set countries = new HashSet(); + final Set countries = new HashSet<>(); countries.add("India"); countries.add("USSR"); countries.add("USA"); @@ -34,7 +37,9 @@ public class DoubleBraceTest { @Test public void whenInitializeUnmodifiableSetWithDoubleBrace_containsElements() { - final Set countries = Collections.unmodifiableSet(Stream.of("India", "USSR", "USA").collect(toSet())); + Set countries = Stream.of("India", "USSR", "USA") + .collect(collectingAndThen(toSet(), Collections::unmodifiableSet)); + assertTrue(countries.contains("India")); }