Skip to content

Commit 02f0f92

Browse files
committed
Polish contribution
See gh-35400
1 parent db9e938 commit 02f0f92

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/ConnectionFactoryUtilsTests.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.r2dbc.connection;
1818

19+
import java.util.List;
20+
1921
import io.r2dbc.spi.R2dbcBadGrammarException;
2022
import io.r2dbc.spi.R2dbcDataIntegrityViolationException;
2123
import io.r2dbc.spi.R2dbcException;
@@ -27,7 +29,8 @@
2729
import org.junit.jupiter.api.Test;
2830
import org.junit.jupiter.params.ParameterizedTest;
2931
import org.junit.jupiter.params.provider.Arguments;
30-
import org.junit.jupiter.params.provider.MethodSource;
32+
import org.junit.jupiter.params.provider.FieldSource;
33+
3134
import org.springframework.dao.CannotAcquireLockException;
3235
import org.springframework.dao.DataAccessResourceFailureException;
3336
import org.springframework.dao.DataIntegrityViolationException;
@@ -39,11 +42,8 @@
3942
import org.springframework.r2dbc.BadSqlGrammarException;
4043
import org.springframework.r2dbc.UncategorizedR2dbcException;
4144

42-
import java.util.stream.Stream;
43-
4445
import static org.assertj.core.api.Assertions.assertThat;
45-
46-
46+
import static org.junit.jupiter.params.provider.Arguments.arguments;
4747

4848
/**
4949
* Tests for {@link ConnectionFactoryUtils}.
@@ -92,34 +92,32 @@ void shouldTranslateNonTransientResourceException() {
9292
assertThat(exception).isExactlyInstanceOf(DataAccessResourceFailureException.class);
9393
}
9494

95-
private static Stream<Arguments> duplicateKeyErrorCodes() {
96-
return Stream.of(
97-
Arguments.of("Oracle", "23505", 0),
98-
Arguments.of("Oracle", "23000", 1),
99-
Arguments.of("SAP HANA", "23000", 301),
100-
Arguments.of("MySQL/MariaDB", "23000", 1062),
101-
Arguments.of("MS SQL Server", "23000", 2601),
102-
Arguments.of("MS SQL Server", "23000", 2627),
103-
Arguments.of("Informix", "23000", -239),
104-
Arguments.of("Informix", "23000", -268)
105-
);
95+
@Test
96+
void shouldTranslateIntegrityViolationException() {
97+
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
98+
new R2dbcDataIntegrityViolationException());
99+
assertThat(exception).isExactlyInstanceOf(DataIntegrityViolationException.class);
106100
}
107101

102+
static final List<Arguments> duplicateKeyErrorCodes = List.of(
103+
arguments("Oracle", "23505", 0),
104+
arguments("Oracle", "23000", 1),
105+
arguments("SAP HANA", "23000", 301),
106+
arguments("MySQL/MariaDB", "23000", 1062),
107+
arguments("MS SQL Server", "23000", 2601),
108+
arguments("MS SQL Server", "23000", 2627),
109+
arguments("Informix", "23000", -239),
110+
arguments("Informix", "23000", -268)
111+
);
112+
108113
@ParameterizedTest
109-
@MethodSource("duplicateKeyErrorCodes")
110-
void shouldTranslateIntegrityViolationException(final String db, String sqlState, final int errorCode) {
114+
@FieldSource("duplicateKeyErrorCodes")
115+
void shouldTranslateIntegrityViolationExceptionToDuplicateKeyException(String db, String sqlState, int errorCode) {
111116
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
112117
new R2dbcDataIntegrityViolationException("reason", sqlState, errorCode));
113118
assertThat(exception).as(db).isExactlyInstanceOf(DuplicateKeyException.class);
114119
}
115120

116-
@Test
117-
void shouldTranslateGenericIntegrityViolationException() {
118-
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
119-
new R2dbcDataIntegrityViolationException());
120-
assertThat(exception).isExactlyInstanceOf(DataIntegrityViolationException.class);
121-
}
122-
123121
@Test
124122
void shouldTranslatePermissionDeniedException() {
125123
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",

0 commit comments

Comments
 (0)