001: package fit.decorator;
002:
003: import java.text.ParseException;
004:
005: import fit.Parse;
006: import fit.decorator.exceptions.InvalidInputException;
007: import fit.decorator.util.TestCaseHelper;
008:
009: public class CopyAndAppendLastRowTest extends FixtureDecoratorTestCase {
010: private static final String FIRST_HTML_ROW = "<tr><td>"
011: + CopyAndAppendLastRow.class.getName()
012: + "</td><td>0</td><td>times</td></tr>";
013: private static final int COUNTER = 5;
014: private FixtureDecorator decorator = new CopyAndAppendLastRow();
015:
016: protected String geDecoratorHTMLRow() {
017: return FIRST_HTML_ROW;
018: }
019:
020: protected int numberOfAssertionsOnDecorator() {
021: return 0;
022: }
023:
024: public void testSetupDecoratorShouldThrowInvalidInputExceptionIfCounterIsNotSpecified()
025: throws ParseException {
026: try {
027: decorator.setupDecorator(new String[0]);
028: fail("Should blow up");
029: } catch (InvalidInputException e) {
030: assertEquals(
031: "Count for number of times to add the last row must be specified",
032: e.getMessage());
033: }
034: }
035:
036: public void testSetupDecoratorShouldAddCounterToSummary()
037: throws Exception {
038: decorator
039: .setupDecorator(new String[] { String.valueOf(COUNTER) });
040: assertEquals(COUNTER, ((Integer) decorator.summary
041: .get(CopyAndAppendLastRow.NUMBER_OF_TIMES)).intValue());
042: }
043:
044: public void testShouldLeaveTableAsItIsIfCounterValueIsZero()
045: throws Exception {
046: String fitPage = "<table>" + FIRST_HTML_ROW
047: + "<tr><td>fit.decorator.TestFixture</td></tr></table>";
048: decorator.doTables(new Parse(fitPage));
049: TestCaseHelper.assertCounts(TestCaseHelper.counts(0, 0, 0, 0),
050: decorator.counts);
051: }
052:
053: public void testShouldAddOneRowIfCounterValueIsOne()
054: throws Exception {
055: String fitPage = "<table><tr><td>"
056: + CopyAndAppendLastRow.class.getName()
057: + "</td><td>1"
058: + "</td><td>times</td></tr><tr><td>eg.Division</td></tr>"
059: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
060: + "<tr><td>10</td><td>2</td><td>5</td></tr></table>";
061: decorator.doTables(new Parse(fitPage));
062: TestCaseHelper.assertCounts(TestCaseHelper.counts(2, 0, 0, 0),
063: decorator.counts);
064: }
065:
066: public void testShouldLeaveTableAsItIsIfTotalRowsAreLessThanThree()
067: throws Exception {
068: String fitPage = "<table><tr><td>"
069: + CopyAndAppendLastRow.class.getName()
070: + "</td>"
071: + "<td>0</td><td>times</td></tr><tr><td>eg.Division</td></tr>"
072: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr></table>";
073: decorator.doTables(new Parse(fitPage));
074: TestCaseHelper.assertCounts(TestCaseHelper.counts(0, 0, 0, 0),
075: decorator.counts);
076: }
077:
078: public void testShouldAppendLastRowCounterNumberOfTimes()
079: throws Exception {
080: String fitPage = "<table><tr><td>"
081: + CopyAndAppendLastRow.class.getName()
082: + "</td><td>"
083: + COUNTER
084: + "</td><td>times</td></tr><tr><td>eg.Division</td></tr>"
085: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
086: + "<tr><td>10</td><td>2</td><td>5</td></tr></table>";
087: decorator.doTable(new Parse(fitPage));
088: TestCaseHelper.assertCounts(TestCaseHelper.counts(COUNTER + 1,
089: 0, 0, 0), decorator.counts);
090: }
091:
092: public void testShouldAppendOnlyTheLastRowCounterNumberOfTimes()
093: throws Exception {
094: String fitPage = "<table><tr><td>"
095: + CopyAndAppendLastRow.class.getName()
096: + "</td><td>"
097: + COUNTER
098: + "</td><td>times</td></tr><tr><td>eg.Division</td></tr>"
099: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
100: + "<tr><td>10</td><td>2</td><td>5</td></tr><tr><td>12.6</td><td>3</td><td>4.2</td></tr>"
101: + "<tr><td>100</td><td>4</td><td>25</td></tr></table>";
102: decorator.doTable(new Parse(fitPage));
103: TestCaseHelper.assertCounts(TestCaseHelper.counts(COUNTER + 3,
104: 0, 0, 0), decorator.counts);
105: }
106:
107: }
|