package de.fitsample.timerecording;

import fit.RowFixture;

/**
 * The RowFixture for the TimeRecording FIT Test.
 * 
 * @author Ralf
 */
public class TimeRecordingRowFixture extends RowFixture {

    /**
     * The TimeRecording instance to test.
     */
    private TimeRecording timeRecording;

    /**
     * Creates the TimeRecordingRowFixture.
     */
    public TimeRecordingRowFixture() {
        timeRecording = TimeRecordingRepository.getInstance().retrieve();
    }

    /**
     * @see fit.RowFixture#query()
     */
    public Object[] query() throws Exception {
        Object[] result = new Object[timeRecording.size()];
        for (int i = 0; i < result.length; i++) {
            result[i] = new TimeRecordRowFixtureAdapter(timeRecording
                    .getRecord(i));
        }
        return result;
    }

    /**
     * @see fit.ColumnFixture#getTargetClass()
     */
    public Class getTargetClass() {
        return TimeRecordRowFixtureAdapter.class;
    }

    /**
     * Overwrite parse() in order to support custom type {@link Time Time}.
     * 
     * @see fit.Fixture#parse(java.lang.String, java.lang.Class)
     */
    public Object parse(String text, Class type) throws Exception {
        if (type == Time.class) {
            return Time.valueOf(text);
        }
        return super.parse(text, type);
    }

}
