Code Search for Developers
 
 
  

ActionFixture.java from MASE: Agile Software Engineering at Krugle


Show ActionFixture.java syntax highlighted

// Modified or written by Object Mentor, Inc. for inclusion with FitNesse.
// Copyright (c) 2002 Cunningham & Cunningham, Inc.
// Released under the terms of the GNU General Public License version 2 or later.package fit;

package fit;

import java.lang.reflect.Method;
import fit.exception.*;

public class ActionFixture extends Fixture
{
  protected Parse cells;
  public static Fixture actor;
  protected static Class empty[] = {};

  // Traversal ////////////////////////////////

  public void doCells(Parse cells)
  {
    this.cells = cells;
    try
    {
      Method action = getClass().getMethod(cells.text(), empty);
      action.invoke(this, empty);
    }
    catch(Exception e)
    {
      exception(cells, e);
    }
  }

  // Actions //////////////////////////////////

  public void start() throws Throwable
  {
    Parse fixture = cells.more;
    if(fixture == null)
      throw new FitFailureException("You must specify a fixture to start.");
    actor = loadFixture(fixture.text());
  }

  public void enter() throws Exception
  {
    Method method = method(1);
    Class type = method.getParameterTypes()[0];
    final Parse argumentCell = cells.more.more;
    if(argumentCell == null)
      throw new FitFailureException("You must specify an argument.");
    String text = argumentCell.text();
    Object[] args;
    try
    {
      args = new Object[]{TypeAdapter.on(actor, type).parse(text)};
    }
    catch(NumberFormatException e)
    {
      throw new CouldNotParseFitFailureException(text, type.getName());
    }
    method.invoke(actor, args);
  }

  public void press() throws Exception
  {
    method(0).invoke(actor, empty);
  }

  public void check() throws Throwable
  {
    TypeAdapter adapter;
    Method theMethod = method(0);
    Class type = theMethod.getReturnType();
    try
    {
      adapter = TypeAdapter.on(actor, theMethod);
    }
    catch(Throwable e)
    {
      throw new FitFailureException("Can not parse return type: " + type.getName());
    }
    Parse checkValueCell = cells.more.more;
    if(checkValueCell == null)
      throw new FitFailureException("You must specify a value to check.");

    check(checkValueCell, adapter);
  }

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

  protected Method method(int args) throws NoSuchMethodException
  {
    final Parse methodCell = cells.more;
    if(methodCell == null)
      throw new FitFailureException("You must specify a method.");
    return method(camel(methodCell.text()), args);
  }

  protected Method method(String test, int args) throws NoSuchMethodException
  {
    if(actor == null)
      throw new FitFailureException("You must start a fixture using the 'start' keyword.");
    Method methods[] = actor.getClass().getMethods();
    Method result = null;
    for(int i = 0; i < methods.length; i++)
    {
      Method m = methods[i];
      if(m.getName().equals(test) && m.getParameterTypes().length == args)
      {
        if(result == null)
        {
          result = m;
        }
        else
        {
          throw new FitFailureException("You can only have one " + test + "(arg) method in your fixture.");
        }
      }
    }
    if(result == null)
    {
      throw new NoSuchMethodFitFailureException(test);
    }
    return result;
  }
}



See more files for this project here

MASE: Agile Software Engineering

The MASE project investigates methods to support the coordination and executable acceptance testing of software projects. Keywords: Agile methods, distributed teams, Extreme Programming. See http://ebe.cpsc.ucalgary.ca/ebe for more information.

Project homepage: http://sourceforge.net/projects/mase
Programming language(s): Java,XML
License: other

  exception/
    AmbiguousActionException.java
    AmbiguousNameFailureException.java
    BooleanMethodFitFailureException.java
    ClassIsNotFixtureException.java
    CouldNotLoadComponentFitFailureException.java
    CouldNotParseFitFailureException.java
    CycleException.java
    ExtraCellsFailureException.java
    FitFailureException.java
    FitFailureExceptionWithHelp.java
    FitMatcherException.java
    FitParseException.java
    FixtureException.java
    IgnoredException.java
    MissingCellsFailureException.java
    MissingFieldFitFailureException.java
    MissingMethodException.java
    MissingRowFailureException.java
    NestedTableExpected.java
    NoDefaultConstructorFixtureException.java
    NoSuchFieldFitFailureException.java
    NoSuchFixtureException.java
    NoSuchMethodFitFailureException.java
    RowWrongWidthException.java
    VoidMethodFitFailureException.java
  ActionFixture.java
  Binding.java
  ColumnFixture.java
  Comment.java
  Counts.java
  FileRunner.java
  FitMatcher.java
  Fixture.java
  FixtureClass.java
  FixtureListener.java
  FixtureLoader.java
  FixtureName.java
  GracefulNamer.java
  ImportFixture.java
  NullFixtureListener.java
  Parse.java
  PrimitiveFixture.java
  RowFixture.java
  ScientificDouble.java
  SummaryFixture.java
  TestRunner.java
  TimedActionFixture.java
  TypeAdapter.java
  WikiRunner.java