ThreadLocalStack { public void with(T item, WithProcedure procedure) { Preconditions.checkNotNull(item); Preconditions.checkNotNull(procedure); push(item); try { procedure.execute(); } finally { popOrError(); } }  T push(T item); T peek(); T pop(); T popOrError(); T get(); T getOrError(); void set(T item); void remove(); void with(T item, WithProcedure procedure);  }
@Test public void with() { String item = UUID.randomUUID().toString(); stack.with(item, () -> assertThat(stack.get(), equalTo(item))); assertThat(stack.pop(), equalTo(INITIAL_VALUE)); }