001: package fit.decorator.performance;
002:
003: import java.text.ParseException;
004:
005: import fit.ColumnFixture;
006: import fit.Counts;
007: import fit.Parse;
008: import fit.decorator.FixtureDecoratorTestCase;
009: import fit.decorator.Loop;
010: import fit.decorator.exceptions.InvalidInputException;
011: import fit.decorator.util.TestCaseHelper;
012:
013: public class MaxTimeTest extends FixtureDecoratorTestCase {
014: private static final String FIRST_HTML_ROW = "<tr><td>"
015: + MaxTime.class.getName()
016: + "</td><td>100</td><td>milliseconds</td></tr>";
017: private MaxTime decorator = new MaxTime();
018:
019: public void testRunShouldMeasureTimeTakenToExecuteDoTableMethodOnGivenFixture()
020: throws Exception {
021: String fitPage = "<table><tr><td>eg.Division</td></tr>"
022: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
023: + "<tr><td>100</td><td>4</td><td>25</td></tr></table>";
024: MaxTime fixture = new MaxTime(stopWatch);
025: fixture.run(new ColumnFixture(), new Parse(fitPage));
026: assertEquals(ELAPSED, ((Long) fixture.summary
027: .get(MaxTime.ACTUAL_TIME_TAKEN)).longValue());
028: }
029:
030: public void testSetupDecoratorMustThrowInvalidInputExceptionIfMaxTimeIsNotSpecified()
031: throws ParseException {
032: try {
033: decorator.setupDecorator(new String[0]);
034: fail("Should blow up ");
035: } catch (InvalidInputException e) {
036: // expected
037: }
038: }
039:
040: public void testSetupDecoratorShouldAddMaxTimeToSummary()
041: throws Exception {
042: decorator.setupDecorator(new String[] { "80" });
043: assertEquals(80, ((Long) decorator.summary
044: .get(MaxTime.MAX_TIME)).longValue());
045: }
046:
047: public void testShouldFailIfActualExecutionTimeIsGreaterThanMaxtime()
048: throws Exception {
049: String fitPage = "<table><tr><td>"
050: + MaxTime.class.getName()
051: + "</td><td>19</td><td>milliseconds</td>"
052: + "</tr><tr><td>eg.Division</td></tr>"
053: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
054: + "<tr><td>10</td><td>2</td><td>5</td></tr><tr><td>12.6</td><td>3</td><td>4.2</td></tr>"
055: + "<tr><td>100</td><td>4</td><td>25</td></tr></table>";
056: Counts expected = TestCaseHelper.counts(3, 1, 0, 0);
057: executeAndAssert(expected, fitPage, new MaxTime(stopWatch));
058: }
059:
060: public void testShouldPassIfActualExecutionTimeIsEqualToMaxtime()
061: throws Exception {
062: String fitPage = "<table><tr><td>"
063: + MaxTime.class.getName()
064: + "</td><td>20</td><td>milliseconds</td></tr><tr><td>eg.Division</td></tr>"
065: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
066: + "<tr><td>10</td><td>2</td><td>5</td></tr><tr><td>12.6</td><td>3</td><td>4.2</td></tr>"
067: + "<tr><td>100</td><td>4</td><td>25</td></tr></table>";
068: Counts expected = TestCaseHelper.counts(4, 0, 0, 0);
069: executeAndAssert(expected, fitPage, new MaxTime(stopWatch));
070: }
071:
072: public void testShouldPassIfActualExecutionTimeIsLessThanMaxtime()
073: throws Exception {
074: String fitPage = "<table><tr><td>"
075: + MaxTime.class.getName()
076: + "</td><td>80</td><td>milliseconds</td></tr><tr><td>eg.Division</td></tr>"
077: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
078: + "<tr><td>10</td><td>2</td><td>5</td></tr><tr><td>12.6</td><td>3</td><td>4.2</td></tr>"
079: + "<tr><td>100</td><td>4</td><td>25</td></tr></table>";
080: Counts expected = TestCaseHelper.counts(4, 0, 0, 0);
081: executeAndAssert(expected, fitPage, new MaxTime(stopWatch));
082: }
083:
084: public void testShouldWorkIfFitureDecoratorsArePiped()
085: throws Exception {
086: String fitPage = "<table><tr><td>"
087: + MaxTime.class.getName()
088: + "</td><td>80</td><td>milliseconds</td></tr><tr><td>"
089: + Loop.class.getName()
090: + "</td><td>3</td><td>time</td></tr><tr><td>"
091: + MaxTime.class.getName()
092: + "</td><td>80</td><td>milliseconds</td></tr><tr><td>eg.Division</td></tr>"
093: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
094: + "<tr><td>10</td><td>2</td><td>5</td></tr><tr><td>12.6</td><td>3</td><td>4.2</td></tr>"
095: + "<tr><td>100</td><td>4</td><td>25</td></tr></table>";
096: Counts expected = TestCaseHelper.counts(13, 0, 0, 0);
097: executeAndAssert(expected, fitPage, new MaxTime(stopWatch));
098: }
099:
100: protected String geDecoratorHTMLRow() {
101: return FIRST_HTML_ROW;
102: }
103:
104: protected int numberOfAssertionsOnDecorator() {
105: return 1;
106: }
107: }
|