Skip to content

Commit b1e9703

Browse files
committed
#140 - Polishing.
Reduce assertions on numeric fields to contain a Number subtype.
1 parent 776044d commit b1e9703

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ target/
88
.sonar4clipse
99
*.sonar4clipseExternals
1010
*.graphml
11+
*.json

src/test/java/org/springframework/data/r2dbc/core/AbstractDatabaseClientIntegrationTests.java

+14-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import javax.sql.DataSource;
2727

28+
import org.assertj.core.api.Condition;
2829
import org.junit.Before;
2930
import org.junit.Test;
3031

@@ -110,7 +111,7 @@ public void executeInsert() {
110111
.expectNext(1) //
111112
.verifyComplete();
112113

113-
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).containsEntry("id", 42055);
114+
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
114115
}
115116

116117
@Test // gh-2
@@ -121,9 +122,9 @@ public void shouldTranslateDuplicateKeyException() {
121122
executeInsert();
122123

123124
databaseClient.execute(getInsertIntoLegosetStatement()) //
124-
.bind(0, 42055) //
125-
.bind(1, "SCHAUFELRADBAGGER") //
126-
.bindNull(2, Integer.class) //
125+
.bind("id", 42055) //
126+
.bind("name", "SCHAUFELRADBAGGER") //
127+
.bindNull("manual", Integer.class) //
127128
.fetch().rowsUpdated() //
128129
.as(StepVerifier::create) //
129130
.expectErrorSatisfies(exception -> assertThat(exception) //
@@ -166,7 +167,7 @@ public void insert() {
166167
.expectNext(1) //
167168
.verifyComplete();
168169

169-
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).containsEntry("id", 42055);
170+
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
170171
}
171172

172173
@Test // gh-2
@@ -182,7 +183,7 @@ public void insertWithoutResult() {
182183
.as(StepVerifier::create) //
183184
.verifyComplete();
184185

185-
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).containsEntry("id", 42055);
186+
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
186187
}
187188

188189
@Test // gh-2
@@ -203,7 +204,7 @@ public void insertTypedObject() {
203204
.expectNext(1) //
204205
.verifyComplete();
205206

206-
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).containsEntry("id", 42055);
207+
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
207208
}
208209

209210
@Test // gh-64
@@ -456,6 +457,12 @@ public void selectTypedLater() {
456457
.verifyComplete();
457458
}
458459

460+
private Condition<? super Object> numberOf(int expected) {
461+
return new Condition<>(it -> {
462+
return it instanceof Number && ((Number) it).intValue() == expected;
463+
}, "Number %d", expected);
464+
}
465+
459466
@Data
460467
@Table("legoset")
461468
static class LegoSet {

src/test/java/org/springframework/data/r2dbc/core/AbstractTransactionalDatabaseClientIntegrationTests.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.concurrent.ArrayBlockingQueue;
2525

2626
import io.r2dbc.spi.ConnectionFactory;
27+
import org.assertj.core.api.Condition;
2728
import org.junit.After;
2829
import org.junit.Before;
2930
import org.junit.Test;
@@ -156,7 +157,7 @@ public void executeInsertInManagedTransaction() {
156157
.expectNext(1) //
157158
.verifyComplete();
158159

159-
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).containsEntry("id", 42055);
160+
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
160161
}
161162

162163
@Test // gh-2
@@ -174,7 +175,7 @@ public void executeInsertInAutoCommitTransaction() {
174175
.expectNext(1) //
175176
.verifyComplete();
176177

177-
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).containsEntry("id", 42055);
178+
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
178179
}
179180

180181
@Test // gh-2
@@ -313,6 +314,12 @@ public void shouldRollbackTransactionUsingManagedTransactions() {
313314
assertThat(count).isEqualTo(0);
314315
}
315316

317+
private Condition<? super Object> numberOf(int expected) {
318+
return new Condition<>(it -> {
319+
return it instanceof Number && ((Number) it).intValue() == expected;
320+
}, "Number %d", expected);
321+
}
322+
316323
@Configuration
317324
@EnableTransactionManagement
318325
static class Config extends AbstractR2dbcConfiguration {

src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryIntegrationTests.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import javax.sql.DataSource;
3434

35+
import org.assertj.core.api.Condition;
3536
import org.junit.Before;
3637
import org.junit.Test;
3738

@@ -198,7 +199,13 @@ public void shouldInsertItemsTransactional() {
198199
nonTransactional.as(StepVerifier::create).expectNext(Collections.singletonMap("count", 2L)).verifyComplete();
199200

200201
Map<String, Object> count = jdbc.queryForMap("SELECT count(*) AS count FROM legoset");
201-
assertThat(count).containsEntry("count", 2L);
202+
assertThat(count).hasEntrySatisfying("count", numberOf(2));
203+
}
204+
205+
private Condition<? super Object> numberOf(int expected) {
206+
return new Condition<>(it -> {
207+
return it instanceof Number && ((Number) it).intValue() == expected;
208+
}, "Number %d", expected);
202209
}
203210

204211
@NoRepositoryBean

0 commit comments

Comments
 (0)