Loading ...
Sorry, an error occurred while loading the content.

RE: [fitnesse] Looping Action Fixture

Expand Messages
  • Micah Martin
    Cool. More goodies to add to FitNesse! Micah ... Micah Martin - micah@objectmentor.com Software Developer - Object Mentor, Inc. www.objectmentor.com
    Message 1 of 2 , Jun 30, 2003
    View Source
    • 0 Attachment
      Cool. More goodies to add to FitNesse!

      Micah

      -------------------------------------------------------------------
      Micah Martin - micah@...
      Software Developer - Object Mentor, Inc.
      www.objectmentor.com



      > -----Original Message-----
      > From: Michael Feathers [mailto:mfeathers@...]
      > Sent: Monday, June 30, 2003 9:37 PM
      > To: fitnesse@yahoogroups.com
      > Subject: [fitnesse] Looping Action Fixture
      >
      >
      >
      > I forgot who asked about this, but I was tinkering around tonight and
      > decided to make a looping action fixture.
      >
      > This class does a do/while. Nesting is allowed. "do" is an action
      > without arguments. "while" accepts the name of a method on the actor
      > class that returns a boolean. Because "do" and "while" are keywords
      > in Java, I decorate the names.
      >
      > Not as clean as it would be if I didn't inherit from ActionFixture,
      > but pretty fun to do. If anyone wants the test cases, let me know.
      > Here is the source:
      >
      >
      > import java.lang.reflect.*;
      > import java.util.Stack;
      > import fit.*;
      >
      >
      > public class LoopingActionFixture extends ActionFixture {
      >
      > Stack loopContexts = new Stack();
      > Parse rows;
      >
      > boolean isSpecialName(String name) {
      > return name.equals("do") || name.equals("while");
      > }
      >
      > Method getAction(String name) throws
      > SecurityException, NoSuchMethodException {
      > String methodName = isSpecialName(name) ?
      > ("action_" + name) : name;
      > return getClass().getMethod(methodName, empty);
      > }
      >
      > public void doRows(Parse rows) {
      > this.rows = rows;
      > while (this.rows != null) {
      > doRow(this.rows);
      > this.rows = this.rows.more;
      > }
      > }
      >
      > public void doCells(Parse cells) {
      > this.cells = cells;
      > try {
      > Method action = getAction(cells.text());
      > action.invoke(this, empty);
      > } catch (Exception e) {
      > exception(cells, e);
      > }
      > }
      > public void action_do() {
      > loopContexts.push(rows);
      > }
      >
      > public void action_while() throws Exception {
      > String methodName = cells.more.text();
      > Method action =
      > actor.getClass().getMethod(methodName, empty);
      > Boolean result = (Boolean)action.invoke(actor, empty);
      > if (result.booleanValue()) {
      > rows = (Parse)loopContexts.peek();
      > }
      > else {
      > loopContexts.pop();
      > }
      > }
      > }
      >
      >
      > Michael Feathers
      > www.objectmentor.com
      >
      >
      > ------------------------ Yahoo! Groups Sponsor
      > ---------------------~-->
      > Looking for the latest Free IT White Papers?
      > Visit SearchMobileComputing.com to access over 500 white papers.
      > Get instant access at SearchMobileComputing.com Today
      > http://us.click.yahoo.com/ZyjvfD/PLNGAA/uitMAA/03wwlB/TM
      > --------------------------------------------------------------
      > -------~->
      >
      > To unsubscribe from this group, send an email to:
      > fitnesse-unsubscribe@yahoogroups.com
      >
      >
      >
      > Your use of Yahoo! Groups is subject to
      > http://docs.yahoo.com/info/terms/
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.