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