Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Row hasValues condition #109

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -3,7 +3,7 @@

<modelVersion>4.0.0</modelVersion>
<artifactId>assertj-db</artifactId>
<version>2.0.2</version>
<version>2.0.3-SNAPSHOT</version>
<packaging>jar</packaging>
<name>AssertJ-DB - Assertions for database</name>
<description>AssertJ-DB - Rich and fluent assertions for testing with database</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public static <A extends AbstractAssert<?>> A hasValues(A assertion, WritableAss
if (!value.isComparisonPossible(object)) {
throw failures.failure(info, shouldBeCompatible(value, object));
}
if (!areEqual(value, expected[index])) {
if (!areEqual(value, object)) {
if (value.getValueType() == ValueType.BYTES) {
throw failures.failure(info, shouldBeEqual(index));
} else {
throw failures.failure(info, shouldBeEqual(index, Values.getRepresentationFromValueInFrontOfExpected(value,
expected[index]),
expected[index]));
object),
object));
}
}
index++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public E getChangesInstance(Changes changes, ChangeType changeType, String table
}

try {
Class clazz = unProxy(myself.getClass());
Class<?> clazz = unProxy(myself.getClass());
Constructor<E> constructor = actualElementClass.getDeclaredConstructor(clazz, Changes.class);
instance = constructor.newInstance(myself, nextChanges);
instance.as(getChangesDescription(changeType, tableName));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/assertj/db/type/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.assertj.db.type;

import org.assertj.core.api.Condition;
import org.assertj.db.type.lettercase.LetterCase;
import org.assertj.db.type.lettercase.WithColumnLetterCase;

Expand Down Expand Up @@ -174,6 +175,9 @@ public String getValueTypeRepresentation() {
* @return {@code true} is comparison is possible.
*/
public boolean isComparisonPossible(Object object) {
if (object instanceof Condition) {
return true;
}
if (valueType == ValueType.BYTES) {
return (object instanceof byte[]);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/assertj/db/util/Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.assertj.db.util;

import org.assertj.core.api.Condition;
import org.assertj.db.exception.AssertJDBException;
import org.assertj.db.type.*;

Expand Down Expand Up @@ -128,6 +129,10 @@ else if (valueType == ValueType.DATE_TIME) {
return object.equals(expected);
}
}
if (expected instanceof Condition) {
Condition<Object> condition = (Condition<Object>) expected;
return condition.matches(value.getValue());
}

return false;
}
Expand Down