Ejemplo n.º 1
0
 /** {@inheritDoc} */
 public MapAssert<K, V> hasSameSizeAs(Iterable<?> other) {
   maps.assertHasSameSizeAs(info, actual, other);
   return this;
 }
Ejemplo n.º 2
0
 /**
  * Verifies that the actual map contains the given entries, in any order.
  *
  * @param entries the given entries.
  * @return {@code this} assertion object.
  * @throws NullPointerException if the given argument is {@code null}.
  * @throws IllegalArgumentException if the given argument is an empty array.
  * @throws NullPointerException if any of the entries in the given array is {@code null}.
  * @throws AssertionError if the actual map is {@code null}.
  * @throws AssertionError if the actual map does not contain the given entries.
  */
 public MapAssert<K, V> contains(MapEntry... entries) {
   maps.assertContains(info, actual, entries);
   return this;
 }
Ejemplo n.º 3
0
 /** {@inheritDoc} */
 public MapAssert<K, V> hasSize(int expected) {
   maps.assertHasSize(info, actual, expected);
   return this;
 }
Ejemplo n.º 4
0
 /** {@inheritDoc} */
 public MapAssert<K, V> hasSameSizeAs(Object[] other) {
   maps.assertHasSameSizeAs(info, actual, other);
   return this;
 }
Ejemplo n.º 5
0
 /** {@inheritDoc} */
 public void isEmpty() {
   maps.assertEmpty(info, actual);
 }
Ejemplo n.º 6
0
 /** {@inheritDoc} */
 public MapAssert<K, V> isNotEmpty() {
   maps.assertNotEmpty(info, actual);
   return this;
 }
Ejemplo n.º 7
0
/**
 * Assertions for <code>{@link Map}</code>s.
 *
 * <p>To create a new instance of this class, invoke <code>{@link Assertions#assertThat(Map)}</code>
 * .
 *
 * @author David DIDIER
 * @author Yvonne Wang
 * @author Alex Ruiz
 * @author Mikhail Mazursky
 * @author Nicolas François
 */
public class MapAssert<K, V> extends AbstractAssert<MapAssert<K, V>, Map<K, V>>
    implements EnumerableAssert<MapAssert<K, V>, MapEntry> {

  @VisibleForTesting Maps maps = Maps.instance();

  protected MapAssert(Map<K, V> actual) {
    super(actual, MapAssert.class);
  }

  /** {@inheritDoc} */
  public void isNullOrEmpty() {
    maps.assertNullOrEmpty(info, actual);
  }

  /** {@inheritDoc} */
  public void isEmpty() {
    maps.assertEmpty(info, actual);
  }

  /** {@inheritDoc} */
  public MapAssert<K, V> isNotEmpty() {
    maps.assertNotEmpty(info, actual);
    return this;
  }

  /** {@inheritDoc} */
  public MapAssert<K, V> hasSize(int expected) {
    maps.assertHasSize(info, actual, expected);
    return this;
  }

  /** {@inheritDoc} */
  public MapAssert<K, V> hasSameSizeAs(Object[] other) {
    maps.assertHasSameSizeAs(info, actual, other);
    return this;
  }

  /** {@inheritDoc} */
  public MapAssert<K, V> hasSameSizeAs(Iterable<?> other) {
    maps.assertHasSameSizeAs(info, actual, other);
    return this;
  }

  /**
   * Verifies that the actual map contains the given entries, in any order.
   *
   * @param entries the given entries.
   * @return {@code this} assertion object.
   * @throws NullPointerException if the given argument is {@code null}.
   * @throws IllegalArgumentException if the given argument is an empty array.
   * @throws NullPointerException if any of the entries in the given array is {@code null}.
   * @throws AssertionError if the actual map is {@code null}.
   * @throws AssertionError if the actual map does not contain the given entries.
   */
  public MapAssert<K, V> contains(MapEntry... entries) {
    maps.assertContains(info, actual, entries);
    return this;
  }

  /**
   * Verifies that the actual map does not contain the given entries.
   *
   * @param entries the given entries.
   * @return {@code this} assertion object.
   * @throws NullPointerException if the given argument is {@code null}.
   * @throws IllegalArgumentException if the given argument is an empty array.
   * @throws AssertionError if the actual map is {@code null}.
   * @throws AssertionError if the actual map contains any of the given entries.
   */
  public MapAssert<K, V> doesNotContain(MapEntry... entries) {
    maps.assertDoesNotContain(info, actual, entries);
    return this;
  }

  /**
   * Verifies that the actual map contains the given key.
   *
   * @param key the given key
   * @throws AssertionError if the actual map is {@code null}.
   * @throws AssertionError if the actual map does not contain the given key.
   */
  public MapAssert<K, V> containsKey(K key) {
    maps.assertContainsKey(info, actual, key);
    return this;
  }

  /**
   * Verifies that the actual map does not contain the given key.
   *
   * @param key the given key
   * @throws AssertionError if the actual map is {@code null}.
   * @throws AssertionError if the actual map contains the given key.
   */
  public MapAssert<K, V> doesNotContainKey(K key) {
    maps.assertDoesNotContainKey(info, actual, key);
    return this;
  }

  /**
   * Verifies that the actual map contains the given value.
   *
   * @param value the value to look for.
   * @throws AssertionError if the actual map is {@code null}.
   * @throws AssertionError if the actual map does not contain the given value.
   */
  public MapAssert<K, V> containsValue(V value) {
    maps.assertContainsValue(info, actual, value);
    return this;
  }

  /**
   * Verifies that the actual map does not contain the given value.
   *
   * @param value the value that should not be in actual map.
   * @throws AssertionError if the actual map is {@code null}.
   * @throws AssertionError if the actual map contains the given value.
   */
  public MapAssert<K, V> doesNotContainValue(V value) {
    maps.assertDoesNotContainValue(info, actual, value);
    return this;
  }

  /** {@inheritDoc} */
  public MapAssert<K, V> usingElementComparator(Comparator<? super MapEntry> customComparator) {
    throw new UnsupportedOperationException(
        "custom element Comparator is not supported for MapEntry comparison");
  }

  /** {@inheritDoc} */
  public MapAssert<K, V> usingDefaultElementComparator() {
    throw new UnsupportedOperationException(
        "custom element Comparator is not supported for MapEntry comparison");
  }
}
Ejemplo n.º 8
0
 /** {@inheritDoc} */
 public void isNullOrEmpty() {
   maps.assertNullOrEmpty(info, actual);
 }
Ejemplo n.º 9
0
 /**
  * Verifies that the actual map does not contain the given value.
  *
  * @param value the value that should not be in actual map.
  * @throws AssertionError if the actual map is {@code null}.
  * @throws AssertionError if the actual map contains the given value.
  */
 public MapAssert<K, V> doesNotContainValue(V value) {
   maps.assertDoesNotContainValue(info, actual, value);
   return this;
 }
Ejemplo n.º 10
0
 /**
  * Verifies that the actual map contains the given value.
  *
  * @param value the value to look for.
  * @throws AssertionError if the actual map is {@code null}.
  * @throws AssertionError if the actual map does not contain the given value.
  */
 public MapAssert<K, V> containsValue(V value) {
   maps.assertContainsValue(info, actual, value);
   return this;
 }
Ejemplo n.º 11
0
 /**
  * Verifies that the actual map does not contain the given key.
  *
  * @param key the given key
  * @throws AssertionError if the actual map is {@code null}.
  * @throws AssertionError if the actual map contains the given key.
  */
 public MapAssert<K, V> doesNotContainKey(K key) {
   maps.assertDoesNotContainKey(info, actual, key);
   return this;
 }
Ejemplo n.º 12
0
 /**
  * Verifies that the actual map contains the given key.
  *
  * @param key the given key
  * @throws AssertionError if the actual map is {@code null}.
  * @throws AssertionError if the actual map does not contain the given key.
  */
 public MapAssert<K, V> containsKey(K key) {
   maps.assertContainsKey(info, actual, key);
   return this;
 }
Ejemplo n.º 13
0
 /**
  * Verifies that the actual map does not contain the given entries.
  *
  * @param entries the given entries.
  * @return {@code this} assertion object.
  * @throws NullPointerException if the given argument is {@code null}.
  * @throws IllegalArgumentException if the given argument is an empty array.
  * @throws AssertionError if the actual map is {@code null}.
  * @throws AssertionError if the actual map contains any of the given entries.
  */
 public MapAssert<K, V> doesNotContain(MapEntry... entries) {
   maps.assertDoesNotContain(info, actual, entries);
   return this;
 }