package com.atlassian.bitbucket.hamcrest;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import java.util.Map;

/**
 * Matcher for testing empty map.
 */
public class IsEmptyMap<K, V> extends TypeSafeMatcher<Map<K, V>> {

    @Override
    public boolean matchesSafely(Map<K, V> map) {
        return map != null && map.isEmpty();
    }

    public void describeTo(Description description) {
        description.appendText("an empty map");
    }

    @Factory
    public static <K, V> Matcher<Map<K, V>> emptyMapOf(Class<K> keyClass, Class<V> valueClass) {
        return new IsEmptyMap<K, V>();
    }

}
