View Javadoc
1   /*
2    *
3    * The DbUnit Database Testing Framework
4    * Copyright (C)2005, DbUnit.org
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library 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 GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   */
21  package org.dbunit.database.search;
22  
23  import static org.hamcrest.CoreMatchers.equalTo;
24  import static org.hamcrest.Matchers.greaterThan;
25  import static org.hamcrest.Matchers.lessThan;
26  import static org.junit.Assert.assertThat;
27  
28  import org.junit.Test;
29  
30  import com.gargoylesoftware.base.testing.EqualsTester;
31  
32  import junit.framework.TestCase;
33  
34  /**
35   * @author gommma
36   * @author Last changed by: $Author$
37   * @version $Revision$ $Date$
38   * @since 2.4.0
39   */
40  public class ForeignKeyRelationshipEdgeTest extends TestCase
41  {
42      private final ForeignKeyRelationshipEdge e1 =
43              new ForeignKeyRelationshipEdge("table1", "table2", "fk_col",
44                      "pk_col");
45      private final ForeignKeyRelationshipEdge equal =
46              new ForeignKeyRelationshipEdge("table1", "table2", "fk_col",
47                      "pk_col");
48      private final ForeignKeyRelationshipEdge notEqual1 =
49              new ForeignKeyRelationshipEdge("table1", "tableOther", "fk_col",
50                      "pk_col");
51      private final ForeignKeyRelationshipEdge notEqual2 =
52              new ForeignKeyRelationshipEdge("table1", "table2", "fk_col_other",
53                      "pk_col");
54  
55      private final ForeignKeyRelationshipEdge equalSubclass =
56              new ForeignKeyRelationshipEdge("table1", "table2", "fk_col",
57                      "pk_col")
58              {
59              };
60  
61      public void testEqualsHashCode()
62      {
63          // Use gsbase "EqualsTester" library for this - easier and less code for
64          // equals/hashCode test
65          new EqualsTester(e1, equal, notEqual1, equalSubclass);
66          new EqualsTester(e1, equal, notEqual2, equalSubclass);
67      }
68  
69      @Test
70      public void testCompareTo()
71      {
72          assertThat("Equal instances have different compareTo.",
73                  e1.compareTo(equal), equalTo(0));
74  
75          assertThat(
76                  "Unequal parent values with equal child values:"
77                          + " first compared after second.",
78                  e1.compareTo(notEqual1), lessThan(0));
79          assertThat(
80                  "Unequal parent values with equal child values:"
81                          + " first compared before second.",
82                  notEqual1.compareTo(e1), greaterThan(0));
83  
84          assertThat(
85                  "Equal parent values with unequal child values:"
86                          + " first compared after second.",
87                  e1.compareTo(notEqual2), lessThan(0));
88          assertThat(
89                  "Equal parent values with unequal child values:"
90                          + " first compared before second.",
91                  notEqual2.compareTo(e1), greaterThan(0));
92      }
93  }