Skip to content

Commit

Permalink
reintroduced public members of Fixture class for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinGijsen committed Jul 6, 2013
1 parent 20d7ef4 commit 33d5e65
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/fit/Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import fit.exception.FitFailureException;


public final class Dispatcher {
public Counts counts;
public class Dispatcher {
public final Map<String, Object> summary;
public Counts counts;

private final FixtureListener listener;

Expand All @@ -39,6 +39,7 @@ String d(long scale) {
}
}


public Dispatcher(FixtureListener listener) {
counts = new Counts();
summary = new HashMap<String, Object>();
Expand All @@ -49,10 +50,17 @@ public Dispatcher() {
this(new NullFixtureListener());
}


public static void setForcedAbort(boolean state) {
forcedAbort = state;
} //Semaphores

@Deprecated
public static boolean aborting() {
return forcedAbort;
} //Semaphores


public void doTables(Parse tables) {
summary.put("run date", new Date());
summary.put("run elapsed time", new RunTime());
Expand Down
57 changes: 57 additions & 0 deletions src/fit/DispatcherTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (C) 2013 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the CPL Common Public License version 1.0.
package fit;

import java.text.ParseException;

import junit.framework.TestCase;


public class DispatcherTest extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
}

public void testRelationalMatching() throws Exception {
final String[][] table = {
{"fitnesse.fixtures.ColumnFixtureTestFixture"},
{"input", "output?"},
{"1", "_>0"}
};
Parse page = executeFixture(table);
String colTwoResult = page.at(0, 2, 1).body;
assertTrue(colTwoResult.contains("<b>1</b>>0"));
String colTwoTag = page.at(0, 2, 1).tag;
assertTrue(colTwoTag.contains("pass"));
}

public static Parse executeFixture(String[][] table) throws ParseException {
String pageString = makeFixtureTable(table);
Parse page = new Parse(pageString);
Dispatcher dispatcher = new Dispatcher();
dispatcher.doTables(page);
return page;
}

private static String makeFixtureTable(String table[][]) {
StringBuffer buf = new StringBuffer();
buf.append("<table>\n");
for (int ri = 0; ri < table.length; ri++) {
buf.append(" <tr>");
String[] row = table[ri];
for (int ci = 0; ci < row.length; ci++) {
String cell = row[ci];
buf.append("<td>").append(cell).append("</td>");
}
buf.append("</tr>\n");
}
buf.append("</table>\n");
return buf.toString();
}
}
87 changes: 86 additions & 1 deletion src/fit/Fixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,103 @@
import fit.exception.FitFailureException;
import fit.exception.FitMatcherException;


public class Fixture {
public Map<String, Object> summary = new HashMap<String, Object>();

public Counts counts = new Counts();

@Deprecated
public FixtureListener listener = new NullFixtureListener();

protected String[] args;

private static final Map<String, Object> symbols = new HashMap<String, Object>();



@Deprecated
public static void setForcedAbort(boolean state) {
Dispatcher.setForcedAbort(state);
} //Semaphores

protected Class<?> getTargetClass() {
return getClass();
}

@Deprecated
public class RunTime extends Dispatcher.RunTime { }

// Traversal //////////////////////////
@Deprecated
public void doTables(Parse tables) {
summary.put("run date", new Date());
summary.put("run elapsed time", new RunTime());
if (tables != null) {
Parse heading = tables.at(0, 0, 0);
if (heading != null) {
try {
Fixture fixture = getLinkedFixtureWithArgs(tables);
fixture.listener = listener;
fixture.interpretTables(tables);
} catch (Throwable e) {
exception(heading, e);
interpretFollowingTables(tables);
}
}
}
listener.tablesFinished(counts);
ClearSymbols();
SemaphoreFixture.ClearSemaphores(); //Semaphores: clear all at end
}

public static void ClearSymbols() {
symbols.clear();
}

@Deprecated
protected void interpretTables(Parse tables) {
try { // Don't create the first fixture again, because creation may do something important.
getArgsForTable(tables); // get them again for the new fixture object
doTable(tables);
} catch (Exception ex) {
exception(tables.at(0, 0, 0), ex);
listener.tableFinished(tables);
return;
}
interpretFollowingTables(tables);
}

@Deprecated
private void interpretFollowingTables(Parse tables) {
listener.tableFinished(tables);
tables = tables.more;
while (tables != null) {
Parse heading = tables.at(0, 0, 0);

if (Dispatcher.aborting()) ignore(heading); //Semaphores: ignore on failed lock
else if (heading != null) {
try {
Fixture fixture = getLinkedFixtureWithArgs(tables);
fixture.doTable(tables);
} catch (Throwable e) {
exception(heading, e);
}
}
listener.tableFinished(tables);
tables = tables.more;
}
}

@Deprecated
protected Fixture getLinkedFixtureWithArgs(Parse tables) throws Throwable {
Parse header = tables.at(0, 0, 0);
Fixture fixture = loadFixture(header.text());
fixture.counts = counts;
fixture.summary = summary;
fixture.getArgsForTable(tables);
return fixture;
}

public static Fixture loadFixture(String fixtureName) throws Throwable {
return FixtureLoader.instance().disgraceThenLoad(fixtureName);
}
Expand Down Expand Up @@ -126,6 +206,11 @@ public boolean isFriendlyException(Throwable exception) {

// Utility //////////////////////////////////

@Deprecated
public String counts() {
return counts.toString();
}

public static String label(String string) {
return " <span class=\"fit_label\">" + string + "</span>";
}
Expand Down
4 changes: 2 additions & 2 deletions src/fit/FixtureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public void testParseDate() throws Exception {
public static Parse executeFixture(String[][] table) throws ParseException {
String pageString = makeFixtureTable(table);
Parse page = new Parse(pageString);
Dispatcher dispatcher = new Dispatcher();
dispatcher.doTables(page);
Fixture fixture = new Fixture();
fixture.doTables(page);
return page;
}

Expand Down

0 comments on commit 33d5e65

Please sign in to comment.