### Question:
Stack { public T replaceTop(T value) { return list.set(list.size() - 1, value); }  void push(T o); T pop(); T replaceTop(T value); T peek(); boolean isEmpty(); int size(); List<T> getList(); static final Stack EMPTY; }### Answer:
@Test public void testReplaceTop() throws Exception { stack.push("a"); stack.push("b"); stack.replaceTop("c"); ReflectionAssert.assertReflectionEquals(new String[]{"a", "c"}, stack.getList().toArray()); stack.replaceTop("d"); stack.pop(); stack.replaceTop("e"); ReflectionAssert.assertReflectionEquals(new String[]{"e"}, stack.getList().toArray()); }
@Test(expectedExceptions = IndexOutOfBoundsException.class) public void testReplaceTop_emptyStack() throws Exception { stack.replaceTop("a"); }