### Question:
DynamicSortedTreeSet extends AbstractSet<E> implements List<E>, Deque<E> { @Override public boolean add(E e) { return map.put(e, e) == null; } DynamicSortedTreeSet();  DynamicSortedTreeSet(Comparator<E> comparator); @Override boolean add(E e); @Override void add(int index, E element); @Override boolean addAll(int index, Collection<? extends E> c); @Override void addFirst(E e); @Override void addLast(E e); @Override void clear(); @Override boolean contains(Object o); @Override Iterator<E> descendingIterator(); @Override E element(); @Override E get(int index); @Override E getFirst(); @Override E getLast(); @Override int indexOf(Object o); @Override boolean isEmpty(); @Override Iterator<E> iterator(); @Override int lastIndexOf(Object o); @Override ListIterator<E> listIterator(); @Override ListIterator<E> listIterator(int index); @Override boolean offer(E e); @Override boolean offerFirst(E e); @Override boolean offerLast(E e); @Override E peek(); @Override E peekFirst(); @Override E peekLast(); @Override E poll(); @Override E pollFirst(); @Override E pollLast(); @Override E pop(); @Override void push(E e); @Override E remove(); @Override E remove(int index); @Override boolean remove(Object o); @Override boolean removeAll(Collection<?> c); @Override E removeFirst(); @Override boolean removeFirstOccurrence(Object o); @Override E removeLast(); @Override boolean removeLastOccurrence(Object o); @Override boolean retainAll(Collection<?> c); @Override E set(int index, E element); @Override int size(); @Override Spliterator<E> spliterator(); @Override List<E> subList(int fromIndex, int toIndex); boolean update(E e);  }### Answer:
@Test public void testNaturalOrder() { DynamicSortedTreeSet<String> queue = new DynamicSortedTreeSet<>(); queue.add("2nd"); queue.add("1st"); queue.add("3rd"); List<String> ordered = new ArrayList<>(queue); assertEquals(Arrays.asList(new String[] { "1st", "2nd", "3rd" }), ordered); }
@Test(expected = ClassCastException.class) public void testUnorderedError() { DynamicSortedTreeSet<NonComparable> queue = new DynamicSortedTreeSet<>(); queue.add(new NonComparable("2nd", 2)); queue.add(new NonComparable("1st", 1)); }
@Test public void testExplicitOrdered() { DynamicSortedTreeSet<TestElem> queue = new DynamicSortedTreeSet<>(new CostComparator()); queue.add(new TestElem("2ndB", 2)); queue.add(new TestElem("2ndA", 2)); queue.add(new TestElem("1st", 1)); queue.add(new TestElem("3rd", 3)); List<String> ordered = new ArrayList<>(); for (TestElem elem : queue) { ordered.add(elem.key); } assertEquals(Arrays.asList(new String[] { "1st", "2ndB", "2ndA", "3rd" }), ordered); }