Class MutatesArgument<Argument,​Type>

  • All Implemented Interfaces:
    Quality<java.util.function.Function<Argument,​Type>>

    public final class MutatesArgument<Argument,​Type>
    extends java.lang.Object
    implements Quality<java.util.function.Function<Argument,​Type>>
    Quality of a non-pure Function that mutates its argument when called.

    Examples

    The following test ensures the function list->list:add adds an element to a given List and returns true when the list content has been changed.

    
     assertThat(list -> list::add,
         mutatesArgument(
             ArrayList::new,
             soIt(iterates("a")),
             when(maps("a", to(true)))));
     

    A common use case is testing mutation of Constructor arguments of mutable classes. Consider a ListAppender Consumer that appends any value to the given list.

    
     assertThat(list -> new ListAppender(list),
         mutatesArgument(
             ArrayList::new,
             soIt(iterates("a")),
             when(consumerThatAccepts("a"))));