datasource-assert

Provide assertions for DataSource using datasource-proxy. Also, include custom assertions(assertThat) for AssertJ and Hamcrest.

License

License

Categories

Categories

Data Net
GroupId

GroupId

net.ttddyy
ArtifactId

ArtifactId

datasource-assert
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

datasource-assert
Provide assertions for DataSource using datasource-proxy. Also, include custom assertions(assertThat) for AssertJ and Hamcrest.
Project URL

Project URL

https://github.com/ttddyy/datasource-assert/
Source Code Management

Source Code Management

https://github.com/ttddyy/datasource-assert

Download datasource-assert

How to add to project

<!-- https://jarcasting.com/artifacts/net.ttddyy/datasource-assert/ -->
<dependency>
    <groupId>net.ttddyy</groupId>
    <artifactId>datasource-assert</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.ttddyy/datasource-assert/
implementation 'net.ttddyy:datasource-assert:1.0'
// https://jarcasting.com/artifacts/net.ttddyy/datasource-assert/
implementation ("net.ttddyy:datasource-assert:1.0")
'net.ttddyy:datasource-assert:jar:1.0'
<dependency org="net.ttddyy" name="datasource-assert" rev="1.0">
  <artifact name="datasource-assert" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.ttddyy', module='datasource-assert', version='1.0')
)
libraryDependencies += "net.ttddyy" % "datasource-assert" % "1.0"
[net.ttddyy/datasource-assert "1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
net.ttddyy : datasource-proxy jar 1.4.4
org.hamcrest : java-hamcrest Optional jar 2.0.0.0
org.assertj : assertj-core Optional jar 2.6.0

test (4)

Group / Artifact Type Version
org.hsqldb : hsqldb jar 2.2.9
org.flywaydb : flyway-core jar 3.2.1
org.mockito : mockito-core jar 1.9.5
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

datasource-assert

Maven Central

datasource-assert provides assertion API for DataSource to validate query executions.

The assertion API is used for assertion methods such as assertEquals in JUnit and TestNG. Also, it comes with support for assertThat in AssertJ and Hamcrest.

Artifacts

Released Version

<dependency>
  <groupId>net.ttddyy</groupId>
  <artifactId>datasource-assert</artifactId>
  <version>[LATEST_VERSION]</version>
</dependency>

Documentation

How to use

Wrap your datasource with ProxyTestDataSource.

@Test
public void myTest() {
  ProxyTestDataSource ds = new ProxyTestDataSource(actualDataSource);
  // rest of test 
}

If you want to reuse the same ProxyTestDataSource instance, you could reset() it between tests.

@After  // @AfterEach, @AfterMethod
public void tearDown() {
   this.ds.reset();
}

Regular assertions

For normal assertions such as JUnit/TestNG assertEquals, use methods from ProxyTestDataSource.

assertEquals(3, ds.getQueryExecutions().size());
PreparedExecution pe = ds.getFirstPrepared();
assertTrue(pe.isSuccess());

See more details on "Usage examples".

AssertJ

Static import assertThat from DataSourceAssertAssertions.

import static net.ttddyy.dsproxy.asserts.assertj.DataSourceAssertAssertions.assertThat;
assertThat(ds.getQueryExecutions()).hasSize(1);
assertThat(ds.getQueryExecutions().get(0)).isStatement().asStatement().query().isEqualTo("SELECT id FROM emp");
assertThat(ds.getFirstPrepared()).containsParam(1, "foo");

See more details on "Usage examples".

Hamcrest

Use matchers from DataSourceAssertMatchers.

assertThat(ds, statementCount(3));
assertThat(ds, executions(1, is(statement())));
assertThat((StatementExecution) statements.get(0), query(is("SELECT id FROM emp")));
assertThat(ds.getFirstPrepared(), paramAsInteger(1, is(100)));

See more details on "Usage examples".

Usage examples

Regular assertions(assertEquals, etc)

With AssertJ

With Hamcrest


Versions

Version
1.0