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

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

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

import javax.swing.JTable;
import java.awt.Component;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import static org.hamcrest.Matchers.equalTo;
import org.hamcrest.TypeSafeMatcher;

public class TableRowCountMatcher extends TypeSafeMatcher {
    private final Matcher rowCountMatcher;

    public TableRowCountMatcher(Matcher rowCountMatcher) {
        this.rowCountMatcher = rowCountMatcher;
    }

    @Override
    public boolean matchesSafely(Component component) {
        return component instanceof JTable
                && matchesSafely((JTable) component);
    }

    public boolean matchesSafely(JTable table) {
        return rowCountMatcher.matches(table.getRowCount());
    }

    public void describeTo(Description description) {
        description.appendText("with row count ");
        rowCountMatcher.describeTo(description);
    }

    public static Matcher withRowCount(int n) {
        return withRowCount(equalTo(n));
    }

    public static Matcher withRowCount(Matcher rowCountMatcher) {
        return new TableRowCountMatcher(rowCountMatcher);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy