Class MultisetAssert<T>

Type Parameters:
T - the type of elements contained in the tested Multiset value
All Implemented Interfaces:
Assert<MultisetAssert<T>,Multiset<? extends T>>, Descriptable<MultisetAssert<T>>, EnumerableAssert<MultisetAssert<T>,T>, ExtensionPoints<MultisetAssert<T>,Multiset<? extends T>>, ObjectEnumerableAssert<MultisetAssert<T>,T>

public class MultisetAssert<T> extends AbstractIterableAssert<MultisetAssert<T>,Multiset<? extends T>,T,ObjectAssert<T>>
Assertions for guava Multiset.

To create an instance of this class, invoke Assertions.assertThat(Multiset)

Author:
Max Daniline
  • Constructor Details

    • MultisetAssert

      protected MultisetAssert(Multiset<? extends T> actual)
  • Method Details

    • contains

      public MultisetAssert<T> contains(int expectedCount, T expected)
      Verifies the actual Multiset contains the given value exactly the given number of times.

      Example :

       Multiset<String> actual = HashMultiset.create();
       actual.add("shoes", 2);
      
       // assertion succeeds
       assertThat(actual).contains(2, "shoes");
      
       // assertions fail
       assertThat(actual).contains(1, "shoes");
       assertThat(actual).contains(3, "shoes");
      Parameters:
      expectedCount - the exact number of times the given value should appear in the set
      expected - the value which to expect
      Returns:
      this MultisetAssert for fluent chaining
      Throws:
      AssertionError - if the actual Multiset is null
      AssertionError - if the actual Multiset contains the given value a number of times different to the given count
    • containsAtLeast

      public MultisetAssert<T> containsAtLeast(int minimumCount, T expected)
      Verifies the actual Multiset contains the given value at least the given number of times.

      Example :

       Multiset<String> actual = HashMultiset.create();
       actual.add("shoes", 2);
      
       // assertions succeed
       assertThat(actual).containsAtLeast(1, "shoes");
       assertThat(actual).containsAtLeast(2, "shoes");
      
       // assertion fails
       assertThat(actual).containsAtLeast(3, "shoes");
      Parameters:
      minimumCount - the minimum number of times the given value should appear in the set
      expected - the value which to expect
      Returns:
      this MultisetAssert for fluent chaining
      Throws:
      AssertionError - if the actual Multiset is null
      AssertionError - if the actual Multiset contains the given value fewer times than the given count
    • containsAtMost

      public MultisetAssert<T> containsAtMost(int maximumCount, T expected)
      Verifies the actual Multiset contains the given value at most the given number of times.

      Example :

       Multiset<String> actual = HashMultiset.create();
       actual.add("shoes", 2);
      
       // assertions succeed
       assertThat(actual).containsAtMost(3, "shoes");
       assertThat(actual).containsAtMost(2, "shoes");
      
       // assertion fails
       assertThat(actual).containsAtMost(1, "shoes");
      Parameters:
      maximumCount - the maximum number of times the given value should appear in the set
      expected - the value which to expect
      Returns:
      this MultisetAssert for fluent chaining
      Throws:
      AssertionError - if the actual Multiset is null
      AssertionError - if the actual Multiset contains the given value more times than the given count
    • toAssert

      protected ObjectAssert<T> toAssert(T value, String description)
      Specified by:
      toAssert in class AbstractIterableAssert<MultisetAssert<T>,Multiset<? extends T>,T,ObjectAssert<T>>
    • newAbstractIterableAssert

      protected MultisetAssert<T> newAbstractIterableAssert(Iterable<? extends T> iterable)
      Specified by:
      newAbstractIterableAssert in class AbstractIterableAssert<MultisetAssert<T>,Multiset<? extends T>,T,ObjectAssert<T>>