Skip to content

Commit

Permalink
(#29) Added some equals and hash code implementations. Removed atomic…
Browse files Browse the repository at this point in the history
… integer from equals in DataSet
  • Loading branch information
svettwer committed Feb 7, 2019
1 parent 4638edf commit e210cf4
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.Executor;

Expand Down Expand Up @@ -439,4 +440,28 @@ public <T> T unwrap(final Class<T> iface) throws SQLException {
public boolean isWrapperFor(final Class<?> iface) throws SQLException {
return false;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof JdbcConnection)) return false;
final JdbcConnection that = (JdbcConnection) o;
return closed == that.closed &&
Objects.equals(httpClient, that.httpClient) &&
Objects.equals(serverUrl, that.serverUrl);
}

@Override
public int hashCode() {
return Objects.hash(httpClient, serverUrl, closed);
}

@Override
public String toString() {
return "JdbcConnection{" +
"httpClient=" + httpClient +
", serverUrl='" + serverUrl + '\'' +
", closed=" + closed +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.sql.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.Objects;

/**
* @author Christoph Deppisch
*/
public class JdbcStatement implements Statement {

private final HttpClient httpClient;
Expand Down Expand Up @@ -377,10 +377,26 @@ public boolean isWrapperFor(final Class<?> iface) throws SQLException {
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!(o instanceof JdbcStatement)) return false;
final JdbcStatement that = (JdbcStatement) o;
return Objects.equals(httpClient, that.httpClient) &&
Objects.equals(serverUrl, that.serverUrl) &&
Objects.equals(connection, that.connection) &&
Objects.equals(dataSet, that.dataSet);
}

@Override
public int hashCode() {
return Objects.hash(httpClient, serverUrl, connection, dataSet);
}

@Override
public String toString() {
return "JdbcStatement{" +
"httpClient=" + httpClient +
", serverUrl='" + serverUrl + '\'' +
", connection=" + connection +
", dataSet=" + dataSet +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ public boolean equals(final Object o) {
if (!(o instanceof DataSet)) return false;
final DataSet dataSet = (DataSet) o;
return closed == dataSet.closed &&
Objects.equals(rows, dataSet.rows) &&
Objects.equals(cursor, dataSet.cursor);
Objects.equals(rows, dataSet.rows);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.consol.citrus.db.driver;

import com.jparams.verifier.tostring.ToStringVerifier;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
Expand Down Expand Up @@ -330,4 +332,14 @@ public void testPrepareStatementIoExceptionIsWrappedInSqlException() throws Exce
//THEN
//Exception is thrown
}

@Test
public void testToString(){
ToStringVerifier.forClass(JdbcStatement.class);
}

@Test
public void equalsContract(){
EqualsVerifier.forClass(JdbcStatement.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@

package com.consol.citrus.db.driver;

import org.apache.http.*;
import com.jparams.verifier.tostring.ToStringVerifier;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.message.BasicHeader;
import org.mockito.Mockito;
Expand All @@ -29,7 +34,9 @@
import java.sql.SQLException;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

Expand Down Expand Up @@ -241,4 +248,14 @@ public void testCloseIoExceptionIsWrappedInSqlException() throws Exception{
//THEN
//Exception is thrown
}

@Test
public void testToString(){
ToStringVerifier.forClass(JdbcStatement.class);
}

@Test
public void equalsContract(){
EqualsVerifier.forClass(JdbcStatement.class);
}
}

0 comments on commit e210cf4

Please sign in to comment.