#140 - Polishing.
Reduce assertions on numeric fields to contain a Number subtype.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,3 +8,4 @@ target/
|
||||
.sonar4clipse
|
||||
*.sonar4clipseExternals
|
||||
*.graphml
|
||||
*.json
|
||||
|
||||
@@ -25,6 +25,7 @@ import reactor.test.StepVerifier;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -110,7 +111,7 @@ public abstract class AbstractDatabaseClientIntegrationTests extends R2dbcIntegr
|
||||
.expectNext(1) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).containsEntry("id", 42055);
|
||||
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
|
||||
}
|
||||
|
||||
@Test // gh-2
|
||||
@@ -121,9 +122,9 @@ public abstract class AbstractDatabaseClientIntegrationTests extends R2dbcIntegr
|
||||
executeInsert();
|
||||
|
||||
databaseClient.execute(getInsertIntoLegosetStatement()) //
|
||||
.bind(0, 42055) //
|
||||
.bind(1, "SCHAUFELRADBAGGER") //
|
||||
.bindNull(2, Integer.class) //
|
||||
.bind("id", 42055) //
|
||||
.bind("name", "SCHAUFELRADBAGGER") //
|
||||
.bindNull("manual", Integer.class) //
|
||||
.fetch().rowsUpdated() //
|
||||
.as(StepVerifier::create) //
|
||||
.expectErrorSatisfies(exception -> assertThat(exception) //
|
||||
@@ -166,7 +167,7 @@ public abstract class AbstractDatabaseClientIntegrationTests extends R2dbcIntegr
|
||||
.expectNext(1) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).containsEntry("id", 42055);
|
||||
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
|
||||
}
|
||||
|
||||
@Test // gh-2
|
||||
@@ -182,7 +183,7 @@ public abstract class AbstractDatabaseClientIntegrationTests extends R2dbcIntegr
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).containsEntry("id", 42055);
|
||||
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
|
||||
}
|
||||
|
||||
@Test // gh-2
|
||||
@@ -203,7 +204,7 @@ public abstract class AbstractDatabaseClientIntegrationTests extends R2dbcIntegr
|
||||
.expectNext(1) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).containsEntry("id", 42055);
|
||||
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
|
||||
}
|
||||
|
||||
@Test // gh-64
|
||||
@@ -456,6 +457,12 @@ public abstract class AbstractDatabaseClientIntegrationTests extends R2dbcIntegr
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
private Condition<? super Object> numberOf(int expected) {
|
||||
return new Condition<>(it -> {
|
||||
return it instanceof Number && ((Number) it).intValue() == expected;
|
||||
}, "Number %d", expected);
|
||||
}
|
||||
|
||||
@Data
|
||||
@Table("legoset")
|
||||
static class LegoSet {
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Queue;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
|
||||
import io.r2dbc.spi.ConnectionFactory;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -156,7 +157,7 @@ public abstract class AbstractTransactionalDatabaseClientIntegrationTests extend
|
||||
.expectNext(1) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).containsEntry("id", 42055);
|
||||
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
|
||||
}
|
||||
|
||||
@Test // gh-2
|
||||
@@ -174,7 +175,7 @@ public abstract class AbstractTransactionalDatabaseClientIntegrationTests extend
|
||||
.expectNext(1) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).containsEntry("id", 42055);
|
||||
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
|
||||
}
|
||||
|
||||
@Test // gh-2
|
||||
@@ -313,6 +314,12 @@ public abstract class AbstractTransactionalDatabaseClientIntegrationTests extend
|
||||
assertThat(count).isEqualTo(0);
|
||||
}
|
||||
|
||||
private Condition<? super Object> numberOf(int expected) {
|
||||
return new Condition<>(it -> {
|
||||
return it instanceof Number && ((Number) it).intValue() == expected;
|
||||
}, "Number %d", expected);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
static class Config extends AbstractR2dbcConfiguration {
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -198,7 +199,13 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
|
||||
nonTransactional.as(StepVerifier::create).expectNext(Collections.singletonMap("count", 2L)).verifyComplete();
|
||||
|
||||
Map<String, Object> count = jdbc.queryForMap("SELECT count(*) AS count FROM legoset");
|
||||
assertThat(count).containsEntry("count", 2L);
|
||||
assertThat(count).hasEntrySatisfying("count", numberOf(2));
|
||||
}
|
||||
|
||||
private Condition<? super Object> numberOf(int expected) {
|
||||
return new Condition<>(it -> {
|
||||
return it instanceof Number && ((Number) it).intValue() == expected;
|
||||
}, "Number %d", expected);
|
||||
}
|
||||
|
||||
@NoRepositoryBean
|
||||
|
||||
Reference in New Issue
Block a user