ImmutableStack { public ImmutableStack<T> push(T t) { if (t == null) { return this; } else { return new ImmutableStack<>(t, this); } } ImmutableStack();  ImmutableStack(T head); private  ImmutableStack(T head, ImmutableStack<T> tail); boolean isEmpty(); int size(); T getHead(); ImmutableStack<T> getTail(); ImmutableStack<T> push(T t); ImmutableStack<T> pop(); Stream<T> stream(); boolean contains(WordToken other);  }
@Test public void testPush() { final ImmutableStack<String> initial = new ImmutableStack<>("one"); final ImmutableStack<String> stack = initial.push("two"); assertEquals("two", stack.getHead()); assertSame(initial, stack.getTail()); assertFalse(stack.isEmpty()); assertSame(initial, stack.pop()); assertEquals(2, stack.size()); }