![JAR search and dependency download from the Maven repository](/logo.png)
com.codeborne.xlstest.matchers.ContainsRow Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xls-test Show documentation
Show all versions of xls-test Show documentation
XLS Test: Excel testing library
package com.codeborne.xlstest.matchers;
import com.codeborne.xlstest.XLS;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.hamcrest.Description;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import static java.util.Arrays.asList;
public class ContainsRow extends XLSMatcher {
private final String[] cellTexts;
public ContainsRow(String... cellTexts) {
this.cellTexts = cellTexts;
}
@Override
protected boolean matchesSafely(XLS item) {
for (int i = 0; i < item.excel.getNumberOfSheets(); i++) {
Sheet sheet = item.excel.getSheetAt(i);
for (Row row : sheet) {
Queue expectedTexts = new LinkedList<>(asList(cellTexts));
for (Cell cell : row) {
String expectedText = expectedTexts.peek();
if (getFormattedCellValue(cell).contains(expectedText)) {
expectedTexts.remove();
}
if (expectedTexts.isEmpty()) return true;
}
}
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("a XLS containing row ").appendValue(Arrays.toString(cellTexts));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy