Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>assertj-db</artifactId>
<version>3.0.1</version>
<version>3.0.2-SNAPSHOT</version>

<name>AssertJ-DB - Assertions for database</name>
<description>AssertJ-DB - Rich and fluent assertions for testing with database</description>
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/org/assertj/db/type/Changes.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import java.util.List;
import java.util.function.Consumer;

import org.assertj.core.api.AssertProvider;
import org.assertj.db.api.Assertions;
import org.assertj.db.api.ChangesAssert;
import org.assertj.db.exception.AssertJDBException;
import org.assertj.db.util.ChangeComparator;

Expand Down Expand Up @@ -85,7 +88,7 @@
* @author Régis Pouiller
* @author Julien Roy
*/
public class Changes extends AbstractDbElement<Changes> {
public class Changes extends AbstractDbElement<Changes> implements AssertProvider<ChangesAssert> {

/**
* The list of the tables.
Expand Down Expand Up @@ -679,4 +682,16 @@ public Changes build() {
return new Changes(this.connectionProvider);
}
}

/**
* Makes both AssertJ Core and AssertJ DB assertions able to coexist in the same class with {@link org.assertj.core.api.Assertions org.assertj.core.api.Assertions.assertThat} as the only import necessary.<br/><br/>
* Also works for both <code>BDDAssertions.then</code> static methods from AssertJ Core and AssertJ DB.<br/><br/>
*
* @see org.assertj.core.api.Assertions#assertThat(AssertProvider) &lt;T&gt; org.assertj.core.api.Assertions.assertThat(AssertProvider&lt;T&gt; component)
* @see org.assertj.core.api.BDDAssertions#then(AssertProvider) &lt;T&gt; org.assertj.core.api.BDDAssertions.then(AssertProvider&lt;T&gt; component)
*/
@Override
public ChangesAssert assertThat() {
return Assertions.assertThat(this);
}
}
17 changes: 16 additions & 1 deletion src/main/java/org/assertj/db/type/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import java.util.Arrays;
import java.util.List;

import org.assertj.core.api.AssertProvider;
import org.assertj.db.api.Assertions;
import org.assertj.db.api.RequestAssert;
import org.assertj.db.type.lettercase.LetterCase;

/**
Expand Down Expand Up @@ -62,7 +65,7 @@
* @author Régis Pouiller
* @author Julien Roy
*/
public class Request extends AbstractDbData<Request> {
public class Request extends AbstractDbData<Request> implements AssertProvider<RequestAssert> {

/**
* SQL request to get the values.
Expand Down Expand Up @@ -226,4 +229,16 @@ public Request build() {
return new Request(this.connectionProvider, this.request, this.parameters, this.pksName);
}
}

/**
* Makes both AssertJ Core and AssertJ DB assertions able to coexist in the same class with {@link org.assertj.core.api.Assertions org.assertj.core.api.Assertions.assertThat} as the only import necessary.<br/><br/>
* Also works for both <code>BDDAssertions.then</code> static methods from AssertJ Core and AssertJ DB.<br/><br/>
*
* @see org.assertj.core.api.Assertions#assertThat(AssertProvider) &lt;T&gt; org.assertj.core.api.Assertions.assertThat(AssertProvider&lt;T&gt; component)
* @see org.assertj.core.api.BDDAssertions#then(AssertProvider) &lt;T&gt; org.assertj.core.api.BDDAssertions.then(AssertProvider&lt;T&gt; component)
*/
@Override
public RequestAssert assertThat() {
return Assertions.assertThat(this);
}
}
17 changes: 16 additions & 1 deletion src/main/java/org/assertj/db/type/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.util.Arrays;
import java.util.List;

import org.assertj.core.api.AssertProvider;
import org.assertj.db.api.Assertions;
import org.assertj.db.api.TableAssert;
import org.assertj.db.exception.AssertJDBException;
import org.assertj.db.type.lettercase.LetterCase;
import org.assertj.db.util.NameComparator;
Expand Down Expand Up @@ -73,7 +76,7 @@
* @author Régis Pouiller
* @author Julien Roy
*/
public class Table extends AbstractDbData<Table> {
public class Table extends AbstractDbData<Table> implements AssertProvider<TableAssert> {

/**
* The name of the table.
Expand Down Expand Up @@ -726,4 +729,16 @@ public enum OrderType {
DESC
}
}

/**
* Makes both AssertJ Core and AssertJ DB assertions able to coexist in the same class with {@link org.assertj.core.api.Assertions org.assertj.core.api.Assertions.assertThat} as the only import necessary.<br/><br/>
* Also works for both <code>BDDAssertions.then</code> static methods from AssertJ Core and AssertJ DB.<br/><br/>
*
* @see org.assertj.core.api.Assertions#assertThat(AssertProvider) &lt;T&gt; org.assertj.core.api.Assertions.assertThat(AssertProvider&lt;T&gt; component)
* @see org.assertj.core.api.BDDAssertions#then(AssertProvider) &lt;T&gt; org.assertj.core.api.BDDAssertions.then(AssertProvider&lt;T&gt; component)
*/
@Override
public TableAssert assertThat() {
return Assertions.assertThat(this);
}
}
40 changes: 40 additions & 0 deletions src/test/java/org/assertj/db/type/Changes_AssertThat_Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2015-2025 the original author or authors.
*/
package org.assertj.db.type;

import static org.assertj.core.api.Assertions.assertThat;

import org.assertj.db.api.ChangesAssert;
import org.assertj.db.common.AbstractTest;
import org.junit.Test;

/**
* These tests are on the return from the {@code assertThat} method of {@code Changes}.
* <p>
*
* @author Jonathan Maniquet
*/
public class Changes_AssertThat_Test extends AbstractTest {

/**
* This method tests the result of {@code assertThat} method from {@code Changes}.
*/
@Test
public void test_result_of_assertThat() {
Changes changes = assertDbConnection.changes().request("SELECT actor.name FROM actor").build();

ChangesAssert assertObject = changes.assertThat();
assertThat(assertObject).isNotNull()
.extracting("changes").isSameAs(changes);
}
}
13 changes: 12 additions & 1 deletion src/test/java/org/assertj/db/type/Changes_Constructor_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
*/
package org.assertj.db.type;

import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;

import org.assertj.core.api.Assertions;
import org.assertj.core.api.ListAssert;
import org.assertj.core.api.ObjectAssert;
import org.assertj.db.common.AbstractTest;
import org.junit.Test;

Expand Down Expand Up @@ -193,4 +196,12 @@ public void test_constructor_request() {
assertThat(changes.getTablesAtStartPointList()).isNull();
assertThat(changes.getTablesAtEndPointList()).isNull();
}

private static ObjectAssert<Object> assertThat(Object o) {
return Assertions.assertThat(o);
}

private static <T> ListAssert<Object> assertThat(List<T> list) {
return Assertions.assertThat(list);
}
}
40 changes: 40 additions & 0 deletions src/test/java/org/assertj/db/type/Request_AssertThat_Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2015-2025 the original author or authors.
*/
package org.assertj.db.type;

import static org.assertj.core.api.Assertions.assertThat;

import org.assertj.db.api.RequestAssert;
import org.assertj.db.common.AbstractTest;
import org.junit.Test;

/**
* These tests are on the return from the {@code assertThat} method of {@code Request}.
* <p>
*
* @author Jonathan Maniquet
*/
public class Request_AssertThat_Test extends AbstractTest {

/**
* This method tests the result of {@code assertThat} method from {@code Request}.
*/
@Test
public void test_result_of_assertThat() {
Request request = assertDbConnection.request("SELECT actor.name FROM actor").build();

RequestAssert assertObject = request.assertThat();
assertThat(assertObject).isNotNull()
.extracting("actual").isSameAs(request);
}
}
40 changes: 40 additions & 0 deletions src/test/java/org/assertj/db/type/Table_AssertThat_Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2015-2025 the original author or authors.
*/
package org.assertj.db.type;

import static org.assertj.core.api.Assertions.assertThat;

import org.assertj.db.api.TableAssert;
import org.assertj.db.common.AbstractTest;
import org.junit.Test;

/**
* These tests are on the return from the {@code assertThat} method of {@code Table}.
* <p>
*
* @author Jonathan Maniquet
*/
public class Table_AssertThat_Test extends AbstractTest {

/**
* This method tests the result of {@code assertThat} method from {@code Table}.
*/
@Test
public void test_result_of_assertThat() {
Table table = assertDbConnection.table("actor").build();

TableAssert assertObject = table.assertThat();
assertThat(assertObject).isNotNull()
.extracting("actual").isSameAs(table);
}
}