move unmodifiable set code to java 9 module

This commit is contained in:
mherbaghinyan 2018-12-30 14:19:24 +04:00
parent fb8183d694
commit a89983a65c
2 changed files with 15 additions and 3 deletions

View File

@ -1,4 +1,4 @@
package com.baeldung.set;
package com.baeldung.java9.set;
import com.google.common.collect.ImmutableSet;
@ -21,8 +21,8 @@ public class UnmodifiableSet {
}
private static void java9Of() {
//Set<String> immutable = Set.of("Canada", "USA");
//System.out.println(immutable);
Set<String> immutable = Set.of("Canada", "USA");
System.out.println(immutable);
}
private static void guavaOf() {

View File

@ -1,5 +1,7 @@
package com.baeldung.java9;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
@ -23,4 +25,14 @@ public class SetExamplesUnitTest {
Set<Integer> intSet = Set.of(intArray);
assertEquals(intSet.size(), intArray.length);
}
@Test(expected = UnsupportedOperationException.class)
public void testUnmodifiableSet() {
Set<String> set = new HashSet<>();
set.add("Canada");
set.add("USA");
Set<String> unmodifiableSet = Collections.unmodifiableSet(set);
unmodifiableSet.add("Costa Rica");
}
}