Difference.java

  1. /*
  2.  *
  3.  *  The DbUnit Database Testing Framework
  4.  *  Copyright (C)2002-2008, 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.assertion;

  22. import org.dbunit.dataset.ITable;

  23. /**
  24.  * Value object to hold the difference of a single data cell found while
  25.  * comparing data.
  26.  * <p>
  27.  * Inspired by the XMLUnit framework.
  28.  * </p>
  29.  *
  30.  * @author gommma (gommma AT users.sourceforge.net)
  31.  * @author Last changed by: $Author$
  32.  * @version $Revision$ $Date$
  33.  * @since 2.4.0
  34.  * @since 2.6.0 added failMessage
  35.  */
  36. public class Difference
  37. {
  38.     private ITable expectedTable;
  39.     private ITable actualTable;
  40.     private int rowIndex;
  41.     private String columnName;
  42.     private Object expectedValue;
  43.     private Object actualValue;
  44.     private String failMessage;

  45.     public Difference(final ITable expectedTable, final ITable actualTable,
  46.             final int rowIndex, final String columnName,
  47.             final Object expectedValue, final Object actualValue)
  48.     {
  49.         this(expectedTable, actualTable, rowIndex, columnName, expectedValue,
  50.                 actualValue, "");
  51.     }

  52.     public Difference(final ITable expectedTable, final ITable actualTable,
  53.             final int rowIndex, final String columnName,
  54.             final Object expectedValue, final Object actualValue,
  55.             final String failMessage)
  56.     {
  57.         this.expectedTable = expectedTable;
  58.         this.actualTable = actualTable;
  59.         this.rowIndex = rowIndex;
  60.         this.columnName = columnName;
  61.         this.expectedValue = expectedValue;
  62.         this.actualValue = actualValue;
  63.         this.failMessage = failMessage;
  64.     }

  65.     @Override
  66.     public String toString()
  67.     {
  68.         final StringBuilder sb = new StringBuilder();
  69.         sb.append(getClass().getName()).append("[");
  70.         sb.append("expectedTable=").append(expectedTable);
  71.         sb.append(", actualTable=").append(actualTable);
  72.         sb.append(", rowIndex=").append(rowIndex);
  73.         sb.append(", columnName=").append(columnName);
  74.         sb.append(", expectedValue=").append(expectedValue);
  75.         sb.append(", actualValue=").append(actualValue);
  76.         sb.append(", failMessage=").append(failMessage);
  77.         sb.append("]");
  78.         return sb.toString();
  79.     }

  80.     public ITable getExpectedTable()
  81.     {
  82.         return expectedTable;
  83.     }

  84.     public ITable getActualTable()
  85.     {
  86.         return actualTable;
  87.     }

  88.     public int getRowIndex()
  89.     {
  90.         return rowIndex;
  91.     }

  92.     public String getColumnName()
  93.     {
  94.         return columnName;
  95.     }

  96.     public Object getExpectedValue()
  97.     {
  98.         return expectedValue;
  99.     }

  100.     public Object getActualValue()
  101.     {
  102.         return actualValue;
  103.     }

  104.     public String getFailMessage()
  105.     {
  106.         return failMessage;
  107.     }

  108.     public void setFailMessage(final String failMessage)
  109.     {
  110.         this.failMessage = failMessage;
  111.     }
  112. }