com.mockrunner.mock.jdbc.MockRowId Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Mockrunner is a lightweight framework for unit testing applications
in the J2EE environment. It supports servlets, filters, tag classes
and Struts actions. It includes a JDBC a JMS and a JCA test
framework and can be used to test EJB based applications.
The newest version!
package com.mockrunner.mock.jdbc;
import java.sql.RowId;
import java.util.Arrays;
import com.mockrunner.base.NestedApplicationException;
/**
* Mock implementation of RowId
.
*/
public class MockRowId implements RowId, Cloneable
{
private byte[] rowIdData;
public MockRowId(byte[] data)
{
rowIdData = data.clone();
}
public byte[] getBytes()
{
return rowIdData;
}
public boolean equals(Object otherObject)
{
if(null == otherObject) return false;
if(!otherObject.getClass().equals(this.getClass())) return false;
MockRowId otherRowId = (MockRowId)otherObject;
return Arrays.equals(rowIdData, otherRowId.getBytes());
}
public int hashCode()
{
int value = 17;
for(int ii = 0; ii < rowIdData.length; ii++)
{
value = (31 * value) + rowIdData[ii];
}
return value;
}
public String toString()
{
StringBuffer buffer = new StringBuffer();
buffer.append(this.getClass().getName() + ": [");
for(int ii = 0; ii < rowIdData.length; ii++)
{
buffer.append(rowIdData[ii]);
if(ii < rowIdData.length - 1)
{
buffer.append(", ");
}
}
buffer.append("]");
return buffer.toString();
}
public Object clone()
{
try
{
MockRowId copy = (MockRowId)super.clone();
copy.rowIdData = rowIdData.clone();
return copy;
}
catch(CloneNotSupportedException exc)
{
throw new NestedApplicationException(exc);
}
}
}