package com.ffbit.collectioins; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import java.util.Comparator; import java.util.SortedSet; import java.util.TreeSet; import org.junit.Before; import org.junit.Test; public class SortedSetTest { private final String APPLE = "apple"; private final String APRICOT = "apricot"; private final String BERRY = "berry"; private final String PLUM = "plum"; private final String ZOO = "zoo"; private SortedSet sortedSet; @Before public void init() { sortedSet = new TreeSet(); fill(sortedSet, APPLE, APRICOT, BERRY, PLUM, ZOO); } @Test public void testComparator() { Comparator comparator = sortedSet.comparator(); assertNull(comparator); } @Test public void testFirst() { assertEquals(APPLE, sortedSet.first()); } @Test public void testHeadSet() { SortedSet headSet = new TreeSet(); fill(headSet, APPLE, APRICOT, BERRY); assertEquals(headSet, sortedSet.headSet(PLUM)); } @Test public void testLast() { assertEquals(ZOO, sortedSet.last()); } @Test public void testSubSet() { SortedSet subSet = new TreeSet(); fill(subSet, APRICOT, BERRY, PLUM); assertEquals(subSet, sortedSet.subSet(APRICOT, ZOO)); } @Test public void testTailSet() { SortedSet tailSet = new TreeSet(); fill(tailSet, PLUM, ZOO); assertEquals(tailSet, sortedSet.tailSet(PLUM)); } private void fill(SortedSet set, T...args) { for (T e : args) { set.add(e); } } }