Memento { @SuppressWarnings( "unchecked" ) public static <T extends Item> Memento<T> empty() { return ( Memento<T> )EMPTY_MEMENTO; } Memento( Set<T> items, Optional<T> topItem ); @SuppressWarnings( "unchecked" ) static Memento<T> empty(); Set<T> getItems(); Optional<T> getTopItem();  }
@Test public void constructWithItemsButWithoutTopItem() { Throwable actual = thrownBy( () -> new Memento<>( ALL_ITEMS, Optional.empty() ) ); assertThat( actual ) .hasMessage( TOP_ITEM_IS_MISSING ) .isInstanceOf( IllegalArgumentException.class ); }
@Test public void constructWithNullAsItems() { Throwable actual = thrownBy( () -> new Memento<>( null, Optional.empty() ) ); assertThat( actual ) .hasMessage( ARGUMENT_ITEMS_MUST_NOT_BE_NULL ) .isInstanceOf( IllegalArgumentException.class ); }
@Test public void empty() { Memento<Item> expected = new Memento<>( new HashSet<>(), Optional.empty() ); Memento<Item> actual = Memento.empty(); assertThat( actual ).isEqualTo( expected ); }