-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved over tests for ListOf...SetOf...and ClassUtilities
- Loading branch information
Showing
3 changed files
with
261 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/test/java/com/cedarsoftware/util/CollectionUtilitiesTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.cedarsoftware.util; | ||
|
||
import com.cedarsoftware.util.io.MetaUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class CollectionUtilitiesTests { | ||
static class Rec { | ||
final String s; | ||
final int i; | ||
Rec(String s, int i) { | ||
this.s = s; | ||
this.i = i; | ||
} | ||
|
||
Rec link; | ||
List<Rec> ilinks; | ||
List<Rec> mlinks; | ||
|
||
Map<String, Rec> smap; | ||
} | ||
|
||
@Test | ||
void testListOf() { | ||
final List<String> list = CollectionUtilities.listOf(); | ||
assertEquals(0, list.size()); | ||
} | ||
|
||
@Test | ||
void testListOf_producesImmutableList() { | ||
final List<String> list = CollectionUtilities.listOf(); | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> list.add("One")); | ||
} | ||
|
||
@Test | ||
void testListOfOne() { | ||
final List<String> list = CollectionUtilities.listOf("One"); | ||
assertEquals(1, list.size()); | ||
assertEquals("One", list.get(0)); | ||
} | ||
|
||
@Test | ||
void testListOfTwo() { | ||
final List<String> list = CollectionUtilities.listOf("One", "Two"); | ||
assertEquals(2, list.size()); | ||
assertEquals("One", list.get(0)); | ||
assertEquals("Two", list.get(1)); | ||
} | ||
|
||
@Test | ||
void testListOfThree() { | ||
final List<String> list = CollectionUtilities.listOf("One", "Two", "Three"); | ||
assertEquals(3, list.size()); | ||
assertEquals("One", list.get(0)); | ||
assertEquals("Two", list.get(1)); | ||
assertEquals("Three", list.get(2)); | ||
} | ||
|
||
@Test | ||
void testSetOf() { | ||
final Set<?> set = CollectionUtilities.setOf(); | ||
assertEquals(0, set.size()); | ||
} | ||
|
||
@Test | ||
void testSetOf_producesImmutableSet() { | ||
final Set<String> set = CollectionUtilities.setOf(); | ||
assertThatExceptionOfType(UnsupportedOperationException.class) | ||
.isThrownBy(() -> set.add("One")); | ||
} | ||
|
||
|
||
@Test | ||
void testSetOfOne() { | ||
final Set<String> set = CollectionUtilities.setOf("One"); | ||
assertEquals(1, set.size()); | ||
assertTrue(set.contains("One")); | ||
} | ||
|
||
@Test | ||
public void testSetOfTwo() { | ||
final Set<String> set = CollectionUtilities.setOf("One", "Two"); | ||
assertEquals(2, set.size()); | ||
assertTrue(set.contains("One")); | ||
assertTrue(set.contains("Two")); | ||
} | ||
|
||
@Test | ||
public void testSetOfThree() { | ||
final Set<String> set = CollectionUtilities.setOf("One", "Two", "Three"); | ||
assertEquals(3, set.size()); | ||
assertTrue(set.contains("One")); | ||
assertTrue(set.contains("Two")); | ||
assertTrue(set.contains("Three")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters