Skip to content

Commit 57ff82c

Browse files
committed
HashSet Initialize
1 parent b012b43 commit 57ff82c

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

java-examples/java-core/src/main/java/com/hellokoding/java/collections/HashSetInitializeExample.java renamed to java-examples/java-core/src/test/java/com/hellokoding/java/collections/HashSetInitializeTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.hellokoding.java.collections;
22

3+
import org.junit.Test;
4+
35
import java.util.Arrays;
46
import java.util.HashSet;
57
import java.util.List;
68
import java.util.Set;
79

810
import static org.assertj.core.api.Assertions.assertThat;
911

10-
public class HashSetInitializeExample {
11-
void initializeInMultipleLines() {
12+
public class HashSetInitializeTest {
13+
@Test
14+
public void initializeInMultipleLines() {
1215
// Create a new HashSet
1316
Set<Integer> set = new HashSet<>();
1417

@@ -28,7 +31,8 @@ void initializeInMultipleLines() {
2831
System.out.println(set);
2932
}
3033

31-
void initializeInOneLine() {
34+
@Test
35+
public void initializeInOneLine() {
3236
// Create a new HashSet
3337
Set<Integer> set = new HashSet<>(){{
3438
add(3);
@@ -42,7 +46,8 @@ void initializeInOneLine() {
4246
System.out.println(set);
4347
}
4448

45-
void initializeByAddAll() {
49+
@Test
50+
public void initializeByAddAll() {
4651
// Create a new HashSet
4752
Set<Integer> set = new HashSet<>();
4853

@@ -58,7 +63,8 @@ void initializeByAddAll() {
5863
System.out.println(set);
5964
}
6065

61-
void initializeFromAnotherCollectionWhenCreating() {
66+
@Test
67+
public void initializeFromAnotherCollectionWhenCreating() {
6268
// create and initialize a HashSet from Java 9+ List.of
6369
Set<Integer> set1 = new HashSet<>(List.of(3, 1, 2));
6470
assertThat(set1).hasSize(3);

0 commit comments

Comments
 (0)