All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.objogate.wl.swing.matcher.CollectionSizeMatcher Maven / Gradle / Ivy

The newest version!
package com.objogate.wl.swing.matcher;

import java.util.Collection;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import static org.hamcrest.Matchers.equalTo;
import org.hamcrest.TypeSafeMatcher;

public class CollectionSizeMatcher> extends TypeSafeMatcher {
    private final Matcher sizeMatcher;

    public CollectionSizeMatcher(Matcher sizeMatcher) {
        this.sizeMatcher = sizeMatcher;
    }

    @Override
    public boolean matchesSafely(C collection) {
        return sizeMatcher.matches(collection.size());
    }

    public void describeTo(Description description) {
        description.appendText("a collection with size ").appendDescriptionOf(sizeMatcher);
    }

    @Factory
    public static > Matcher ofSize(Matcher sizeMatcher) {
        return new CollectionSizeMatcher(sizeMatcher);
    }

    @Factory
    public static > Matcher ofSize(int expectedSize) {
        return ofSize(equalTo(expectedSize));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy