View Javadoc

1   /**
2    * Copyright (c) 2002-2015, JWebUnit team.
3    *
4    * This file is part of JWebUnit.
5    *
6    * JWebUnit is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Lesser General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * JWebUnit is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public License
17   * along with JWebUnit.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package net.sourceforge.jwebunit;
20  
21  import junit.framework.TestCase;
22  import net.sourceforge.jwebunit.html.Cell;
23  import net.sourceforge.jwebunit.html.Row;
24  import net.sourceforge.jwebunit.html.Table;
25  
26  /**
27   * Test the methods of Table. Exemple come from <a href="http://www.w3.org/TR/html401/struct/tables.html#h-11.1"> HTML
28   * 4.01 specs</a>.
29   * 
30   * @author Julien Henry
31   */
32  public class TableTest extends TestCase {
33  
34      /**
35       * Reference table used during tests.
36       */
37      private Table table;
38  
39      /**
40       * {@inheritDoc}
41       */
42      public void setUp() throws Exception {
43          super.setUp();
44          Cell[][] cells = new Cell[4][];
45          cells[0] = new Cell[3];
46          cells[0][0] = new Cell("", 1, 2);
47          cells[0][1] = new Cell("Average", 2, 1);
48          cells[0][2] = new Cell("Red eyes", 1, 2);
49          cells[1] = new Cell[2];
50          cells[1][0] = new Cell("height", 1, 1);
51          cells[1][1] = new Cell("width", 1, 1);
52          cells[2] = new Cell[4];
53          cells[2][0] = new Cell("Males", 1, 1);
54          cells[2][1] = new Cell("1.9", 1, 1);
55          cells[2][2] = new Cell("0.003", 1, 1);
56          cells[2][3] = new Cell("40%", 1, 1);
57          cells[3] = new Cell[4];
58          cells[3][0] = new Cell("Females", 1, 1);
59          cells[3][1] = new Cell("1.7", 1, 1);
60          cells[3][2] = new Cell("0.002", 1, 1);
61          cells[3][3] = new Cell("43%", 1, 1);
62          table = new Table(cells);
63      }
64  
65      /**
66       * Test method assertSubTableEquals.
67       * 
68       */
69      public final void testAssertSubTableEquals() {
70          String[] r1 = { "Males", "1.9", "0.003", "40%" };
71          String[] r2 = { "Females", "1.7", "0.002", "43%" };
72          Table sub = new Table();
73          sub.appendRow(new Row(r1));
74          sub.appendRow(new Row(r2));
75          table.assertSubTableEquals(2, sub);
76      }
77  
78      /**
79       * Test method assertSubTableMatch.
80       * 
81       */
82      public final void testAssertSubTableMatch() {
83          String[] r1 = { "Mal(e|r)s", "1\\.?", "0\\.003", "40\\%" };
84          String[] r2 = { "Fem(.)les", "1\\.?", "0[:punct:]002", "43\\%" };
85          Table sub = new Table();
86          sub.appendRow(new Row(r1));
87          sub.appendRow(new Row(r2));
88          table.assertSubTableMatch(2, sub);
89      }
90  }