Package fitnesse.testsystems.slim.tables

Source Code of fitnesse.testsystems.slim.tables.OrderedQueryTable

package fitnesse.testsystems.slim.tables;

import fitnesse.testsystems.ExecutionResult;
import fitnesse.testsystems.slim.SlimTestContext;
import fitnesse.testsystems.slim.Table;
import fitnesse.testsystems.slim.results.SlimTestResult;

import java.util.List;

public class OrderedQueryTable extends QueryTable {
  private int lastMatchedRow = -1;

  public OrderedQueryTable(Table table, String tableId, SlimTestContext slimTestContext) {
    super(table, tableId, slimTestContext);
  }

  @Override
  protected ExecutionResult markRows(QueryResults queryResults, Iterable<MatchedResult> potentialMatchesByScore) {
    int rowCount = table.getRowCount();
    List<Integer> unmatchedResultRows = unmatchedRows(queryResults.getRows().size());

    for (int tableRow = 2; tableRow < rowCount; tableRow++) {
      MatchedResult bestMatch = takeBestMatch(potentialMatchesByScore, tableRow);
      if (bestMatch == null) {
        markMissingRow(tableRow);
      } else {
        markFieldsInMatchedRow(bestMatch.tableRow, bestMatch.resultRow, queryResults);
        lastMatchedRow = bestMatch.resultRow;
        unmatchedResultRows.remove(bestMatch.resultRow);
      }
    }

    return markSurplusRows(queryResults, unmatchedResultRows);
  }

  private MatchedResult takeBestMatch(Iterable<MatchedResult> potentialMatchesByScore, int tableRow) {
    for (MatchedResult bestResult : potentialMatchesByScore) {
      if (bestResult.tableRow == tableRow) {
        removeOtherwiseMatchedResults(potentialMatchesByScore, bestResult);
        return bestResult;
      }
    }
    return null;
  }

  @Override
  protected SlimTestResult markMatch(int tableRow, int matchedRow, int col, String message) {
    SlimTestResult testResult;
    if (col == 0 && matchedRow <= lastMatchedRow) {
      testResult = SlimTestResult.fail(null, message, "out of order: row " + (matchedRow + 1));
    } else {
      testResult = SlimTestResult.pass(message);
    }
    return testResult;
  }
}
TOP

Related Classes of fitnesse.testsystems.slim.tables.OrderedQueryTable

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.