![JAR search and dependency download from the Maven repository](/logo.png)
fitlibraryGeneric.traverse.ReferenceTraverse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fitlibrary Show documentation
Show all versions of fitlibrary Show documentation
FitLibrary provides general-purpose fixtures (and runners) for storytests with Fit and FitNesse.
The newest version!
/*
* Copyright (c) 2006 Rick Mugridge, www.RimuResearch.com
* Released under the terms of the GNU General Public License version 2 or later.
*/
package fitlibraryGeneric.traverse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import fit.exception.FitFailureException;
import fitlibrary.closure.CalledMethodTarget;
import fitlibrary.closure.LookupMethodTargetStandard;
import fitlibrary.exception.IgnoredException;
import fitlibrary.exception.method.MissingMethodException;
import fitlibrary.exception.table.MissingCellsException;
import fitlibrary.global.PlugBoard;
import fitlibrary.table.Cell;
import fitlibrary.table.Row;
import fitlibrary.table.Table;
import fitlibrary.traverse.Traverse;
import fitlibrary.utility.TestResults;
public class ReferenceTraverse extends Traverse {
private static String[] WORD_COUNTS = {
"first", "second", "third", "fourth", "fifth", "sixth", "seventh",
"eigth", "nineth", "tenth"};
private static Map MAP_WORD_TO_INT = new HashMap();
static {
int i = 0;
for (String word : WORD_COUNTS) {
MAP_WORD_TO_INT.put(word,i++);
}
}
public ReferenceTraverse() {
// No SUT
}
public ReferenceTraverse(Object sut) {
super(sut);
}
@Override
public Object interpretAfterFirstRow(Table table, TestResults results) {
table.error(results, new FitFailureException("Not expected"));
return null;
}
public static boolean applicable(Table table) {
if (table.size() == 1)
return isUses(table.row(0).cell(0).text());
return false;
}
private static boolean isUses(String text) {
return text.toLowerCase().equals("use");
}
public Object interpretReference(Table table, TestResults testResults) throws Exception {
return getObject(table.row(0),1,getSystemUnderTest(),testResults);
}
private Object getObject(Row row, int cellNo, Object initialObject, TestResults testResults) {
Object object = initialObject;
boolean last = false;
if (row.cellExists(cellNo+1)) {
Cell nextCell = row.cell(cellNo+1);
if (!nextCell.matchesText("of",this) && !nextCell.matchesText("in",this)) {
nextCell.fail(testResults,"'of' or 'in' expected",this);
throw new IgnoredException();
}
if (!row.cellExists(cellNo+2)) {
nextCell.error(testResults,new MissingCellsException(""));
throw new IgnoredException();
}
object = getObject(row,cellNo+2,object,testResults);
}
else
last = true;
return getReferencedObject(row.cell(cellNo),object,last,testResults);
}
@SuppressWarnings("unchecked")
private Object getReferencedObject(Cell cell, Object object, boolean last, TestResults testResults) {
if (object instanceof List)
return getElementOfList(cell,(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy