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.tests;
20  
21  import static net.sourceforge.jwebunit.junit.JWebUnit.beginAt;
22  import static net.sourceforge.jwebunit.junit.JWebUnit.setBaseUrl;
23  
24  import org.junit.Test;
25  
26  import net.sourceforge.jwebunit.html.Cell;
27  import net.sourceforge.jwebunit.html.Table;
28  
29  /**
30   * Test table equals assertions using expected tables.
31   */
32  public class ExpectedTableAssertionsHtmlTest extends JWebUnitAPITestCase {
33  
34      public void setUp() throws Exception {
35          super.setUp();
36          setBaseUrl(HOST_PATH + "/ExpectedTableAssertionsTest");
37          beginAt("/TableAssertionsTestPageHtml.html");
38      }
39  
40      @Test
41      public void testAssertTableEquals() throws Throwable {
42          Cell[][] cells = new Cell[4][];
43          cells[0] = new Cell[3];
44          cells[0][0] = new Cell("", 1, 2);
45          cells[0][1] = new Cell("Average", 2, 1);
46          cells[0][2] = new Cell("Red eyes", 1, 2);
47          cells[1] = new Cell[2];
48          cells[1][0] = new Cell("height", 1, 1);
49          cells[1][1] = new Cell("weight", 1, 1);
50          cells[2] = new Cell[4];
51          cells[2][0] = new Cell("Males", 1, 1);
52          cells[2][1] = new Cell("1.9", 1, 1);
53          cells[2][2] = new Cell("0.003", 1, 1);
54          cells[2][3] = new Cell("40%", 1, 1);
55          cells[3] = new Cell[4];
56          cells[3][0] = new Cell("Females", 1, 1);
57          cells[3][1] = new Cell("1.7", 1, 1);
58          cells[3][2] = new Cell("0.002", 1, 1);
59          cells[3][3] = new Cell("43%", 1, 1);
60          Table table = new Table(cells);
61          assertPass("assertTableEquals", new Object[] { "myTable", table });
62      }
63  
64      @Test
65      public void testAssertTableEqualsMissingRows() throws Throwable {
66          Cell[][] cells = new Cell[3][];
67          cells[0] = new Cell[3];
68          cells[0][0] = new Cell("", 1, 2);
69          cells[0][1] = new Cell("Average", 2, 1);
70          cells[0][2] = new Cell("Red eyes", 1, 2);
71          cells[1] = new Cell[2];
72          cells[1][0] = new Cell("height", 1, 1);
73          cells[1][1] = new Cell("weight", 1, 1);
74          cells[2] = new Cell[4];
75          cells[2][0] = new Cell("Males", 1, 1);
76          cells[2][1] = new Cell("1.9", 1, 1);
77          cells[2][2] = new Cell("0.003", 1, 1);
78          cells[2][3] = new Cell("40%", 1, 1);
79          Table table = new Table(cells);
80          assertPass("assertTableRowsEqual", new Object[] { "myTable",
81                  Integer.valueOf(0), table });
82          assertFail("assertTableEquals", new Object[] { "myTable", table });
83      }
84  
85  }