Polishing

This commit is contained in:
Juergen Hoeller
2023-10-11 16:10:53 +02:00
parent 87424cd605
commit 86650d1a39
9 changed files with 29 additions and 31 deletions

View File

@@ -302,13 +302,13 @@ public abstract class ConnectionFactoryUtils {
* @return the innermost target Connection, or the passed-in one if not wrapped
* @see Wrapped#unwrap()
*/
@SuppressWarnings({"rawtypes", "unchecked"})
@SuppressWarnings("unchecked")
public static Connection getTargetConnection(Connection con) {
Object conToUse = con;
while (conToUse instanceof Wrapped wrapped) {
conToUse = wrapped.unwrap();
Connection conToUse = con;
while (conToUse instanceof Wrapped<?>) {
conToUse = ((Wrapped<Connection>) conToUse).unwrap();
}
return (Connection) conToUse;
return conToUse;
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -231,7 +231,7 @@ public class SingleConnectionFactory extends DelegatingConnectionFactory
*/
protected Connection getCloseSuppressingConnectionProxy(Connection target) {
return (Connection) Proxy.newProxyInstance(SingleConnectionFactory.class.getClassLoader(),
new Class<?>[] { Connection.class, Wrapped.class }, new CloseSuppressingInvocationHandler(target));
new Class<?>[] {Connection.class, Wrapped.class}, new CloseSuppressingInvocationHandler(target));
}

View File

@@ -186,7 +186,7 @@ final class DefaultDatabaseClient implements DatabaseClient {
*/
private static Connection createConnectionProxy(Connection con) {
return (Connection) Proxy.newProxyInstance(DatabaseClient.class.getClassLoader(),
new Class<?>[] { Connection.class, Wrapped.class },
new Class<?>[] {Connection.class, Wrapped.class},
new CloseSuppressingInvocationHandler(con));
}

View File

@@ -70,7 +70,7 @@ class R2dbcTransactionManagerUnitTests {
@BeforeEach
@SuppressWarnings({"unchecked", "rawtypes"})
@SuppressWarnings({"rawtypes", "unchecked"})
void before() {
when(connectionFactoryMock.create()).thenReturn((Mono) Mono.just(connectionMock));
when(connectionMock.beginTransaction(any(io.r2dbc.spi.TransactionDefinition.class))).thenReturn(Mono.empty());

View File

@@ -57,7 +57,7 @@ class TransactionAwareConnectionFactoryProxyUnitTests {
@BeforeEach
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
void before() {
when(connectionFactoryMock.create()).thenReturn((Mono) Mono.just(connectionMock1),
(Mono) Mono.just(connectionMock2), (Mono) Mono.just(connectionMock3));

View File

@@ -34,13 +34,14 @@ public class MapConnectionFactoryLookupUnitTests {
private static final String CONNECTION_FACTORY_NAME = "connectionFactory";
@Test
public void getConnectionFactoriesReturnsUnmodifiableMap() {
MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup();
Map<String, ConnectionFactory> connectionFactories = lookup.getConnectionFactories();
assertThatThrownBy(() -> connectionFactories.put("",
new DummyConnectionFactory())).isInstanceOf(UnsupportedOperationException.class);
assertThatThrownBy(() -> connectionFactories.put("", new DummyConnectionFactory()))
.isInstanceOf(UnsupportedOperationException.class);
}
@Test
@@ -52,8 +53,8 @@ public class MapConnectionFactoryLookupUnitTests {
MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup();
lookup.setConnectionFactories(connectionFactories);
ConnectionFactory connectionFactory = lookup.getConnectionFactory(CONNECTION_FACTORY_NAME);
assertThat(connectionFactory).isNotNull().isSameAs(expectedConnectionFactory);
assertThat(lookup.getConnectionFactory(CONNECTION_FACTORY_NAME))
.isNotNull().isSameAs(expectedConnectionFactory);
}
@Test
@@ -67,12 +68,12 @@ public class MapConnectionFactoryLookupUnitTests {
lookup.setConnectionFactories(connectionFactories);
lookup.addConnectionFactory(CONNECTION_FACTORY_NAME, expectedConnectionFactory);
ConnectionFactory connectionFactory = lookup.getConnectionFactory(CONNECTION_FACTORY_NAME);
assertThat(connectionFactory).isNotNull().isSameAs(expectedConnectionFactory);
assertThat(lookup.getConnectionFactory(CONNECTION_FACTORY_NAME))
.isNotNull().isSameAs(expectedConnectionFactory);
}
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"rawtypes", "unchecked"})
public void getConnectionFactoryWhereSuppliedMapHasNonConnectionFactoryTypeUnderSpecifiedKey() {
Map connectionFactories = new HashMap<>();
connectionFactories.put(CONNECTION_FACTORY_NAME, new Object());
@@ -86,8 +87,9 @@ public class MapConnectionFactoryLookupUnitTests {
public void getConnectionFactoryWhereSuppliedMapHasNoEntryForSpecifiedKey() {
MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup();
assertThatThrownBy(() -> lookup.getConnectionFactory(CONNECTION_FACTORY_NAME))
.isInstanceOf(ConnectionFactoryLookupFailureException.class);
assertThatThrownBy(
() -> lookup.getConnectionFactory(CONNECTION_FACTORY_NAME)).isInstanceOf(
ConnectionFactoryLookupFailureException.class);
}
}

View File

@@ -84,8 +84,9 @@ public class NamedParameterUtilsUnitTests {
@Test
public void substituteObjectArray() {
MapBindParameterSource namedParams = new MapBindParameterSource(new HashMap<>());
namedParams.addValue("a", Arrays.asList(new Object[] { "Walter", "Heisenberg" },
new Object[] { "Walt Jr.", "Flynn" }));
namedParams.addValue("a",
Arrays.asList(new Object[] {"Walter", "Heisenberg"},
new Object[] {"Walt Jr.", "Flynn"}));
PreparedOperation<?> operation = NamedParameterUtils.substituteNamedParameters(
"xxx :a", BIND_MARKERS, namedParams);
@@ -96,8 +97,9 @@ public class NamedParameterUtilsUnitTests {
@Test
public void shouldBindObjectArray() {
MapBindParameterSource namedParams = new MapBindParameterSource(new HashMap<>());
namedParams.addValue("a", Arrays.asList(new Object[] { "Walter", "Heisenberg" },
new Object[] { "Walt Jr.", "Flynn" }));
namedParams.addValue("a",
Arrays.asList(new Object[] {"Walter", "Heisenberg"},
new Object[] {"Walt Jr.", "Flynn"}));
BindTarget bindTarget = mock();

View File

@@ -32,7 +32,6 @@ class IndexedBindMarkersUnitTests {
@Test
void shouldCreateNewBindMarkers() {
BindMarkersFactory factory = BindMarkersFactory.indexed("$", 0);
BindMarkers bindMarkers1 = factory.create();
BindMarkers bindMarkers2 = factory.create();
@@ -43,7 +42,6 @@ class IndexedBindMarkersUnitTests {
@Test
void shouldCreateNewBindMarkersWithOffset() {
BindTarget bindTarget = mock();
BindMarkers bindMarkers = BindMarkersFactory.indexed("$", 1).create();
BindMarker first = bindMarkers.next();
@@ -60,10 +58,9 @@ class IndexedBindMarkersUnitTests {
@Test
void nextShouldIncrementBindMarker() {
String[] prefixes = { "$", "?" };
String[] prefixes = {"$", "?"};
for (String prefix : prefixes) {
BindMarkers bindMarkers = BindMarkersFactory.indexed(prefix, 0).create();
BindMarker marker1 = bindMarkers.next();
@@ -76,9 +73,7 @@ class IndexedBindMarkersUnitTests {
@Test
void bindValueShouldBindByIndex() {
BindTarget bindTarget = mock();
BindMarkers bindMarkers = BindMarkersFactory.indexed("$", 0).create();
bindMarkers.next().bind(bindTarget, "foo");
@@ -91,7 +86,6 @@ class IndexedBindMarkersUnitTests {
@Test
void bindNullShouldBindByIndex() {
BindTarget bindTarget = mock();
BindMarkers bindMarkers = BindMarkersFactory.indexed("$", 0).create();
bindMarkers.next(); // ignore

View File

@@ -43,7 +43,7 @@ class NamedBindMarkersUnitTests {
}
@ParameterizedTest
@ValueSource(strings = { "$", "?" })
@ValueSource(strings = {"$", "?"})
void nextShouldIncrementBindMarker(String prefix) {
BindMarkers bindMarkers = BindMarkersFactory.named(prefix, "p", 32).create();