All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.greenpepper.extensions.fit.FitDefaultRow Maven / Gradle / Ivy

There is a newer version: 4.2.4
Show newest version
package com.greenpepper.extensions.fit;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.greenpepper.Call;
import com.greenpepper.Example;
import com.greenpepper.Specification;
import com.greenpepper.annotation.Annotations;
import com.greenpepper.call.Annotate;
import com.greenpepper.call.Do;
import com.greenpepper.call.ResultIs;
import com.greenpepper.interpreter.flow.AbstractRow;
import com.greenpepper.interpreter.flow.dowith.Action;
import com.greenpepper.reflect.Fixture;
import com.greenpepper.util.CollectionUtil;
import com.greenpepper.util.Group;

/**
 * 

FitDefaultRow class.

* * @author oaouattara * @version $Id: $Id */ public class FitDefaultRow extends AbstractRow { private Fixture fitFixture; private boolean timed; /** *

Constructor for FitDefaultRow.

* * @param fitFixture a {@link com.greenpepper.reflect.Fixture} object. * @param fixture a {@link com.greenpepper.reflect.Fixture} object. * @param timed a {@link java.lang.Boolean} object. */ public FitDefaultRow(Fixture fitFixture, Fixture fixture, Boolean timed) { super(fixture); this.fitFixture = fitFixture; this.timed = timed; } /** {@inheritDoc} */ public void interpret(Specification table) { Example row = table.nextExample(); Action action = Action.parse(actionCells(row)); Date start = new Date(); try { Call call = action.checkAgainst(fitFixture != null ? fitFixture : fixture); call.will(Do.both(Annotate.right(Group.composedOf(keywordCells(row)))).and(countRowOf(table).right())).when(ResultIs.equalTo(true)); call.will(Do.both(Annotate.wrong(Group.composedOf(keywordCells(row)))).and(countRowOf(table).wrong())).when(ResultIs.equalTo(false)); call.will(Do.both(Annotate.exception(CollectionUtil.first(keywordCells(row)))).and(countRowOf(table).exception())).when(ResultIs.exception()); call.execute(); } catch (Exception e) { CollectionUtil.first(keywordCells(row)).annotate(Annotations.exception(e)); reportException(table); } finally { if(timed) { long split = new Date().getTime() - start.getTime(); row.addChild().setContent(Fit.format.format(start)); row.addChild().setContent(split<1000 ? " " : Double.toString((split)/1000.0)); } } } /** {@inheritDoc} */ public List actionCells(Example row) { List defaultRow = new ArrayList(); defaultRow.add(row.firstChild()); return defaultRow; } private List keywordCells(Example row) { return CollectionUtil.even(row.firstChild()); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy