Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Oct 11, 2023
1 parent 87424cd commit 86650d1
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@ private static boolean connectionEquals(ConnectionHolder conHolder, Connection p
* @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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -231,7 +231,7 @@ protected Mono<Connection> prepareConnection(Connection connection) {
*/
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));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private ConnectionFactory obtainConnectionFactory() {
*/
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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,8 +53,8 @@ public void shouldLookupConnectionFactory() {
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
Expand All @@ -67,12 +68,12 @@ public void addingConnectionFactoryPermitsOverride() {
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());
Expand All @@ -86,8 +87,9 @@ public void getConnectionFactoryWhereSuppliedMapHasNonConnectionFactoryTypeUnder
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ public void substituteNamedParameters() {
@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);
Expand All @@ -96,8 +97,9 @@ public void substituteObjectArray() {
@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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class IndexedBindMarkersUnitTests {
@Test
void shouldCreateNewBindMarkers() {
BindMarkersFactory factory = BindMarkersFactory.indexed("$", 0);

BindMarkers bindMarkers1 = factory.create();
BindMarkers bindMarkers2 = factory.create();

Expand All @@ -43,7 +42,6 @@ void shouldCreateNewBindMarkers() {
@Test
void shouldCreateNewBindMarkersWithOffset() {
BindTarget bindTarget = mock();

BindMarkers bindMarkers = BindMarkersFactory.indexed("$", 1).create();

BindMarker first = bindMarkers.next();
Expand All @@ -60,10 +58,9 @@ void shouldCreateNewBindMarkersWithOffset() {

@Test
void nextShouldIncrementBindMarker() {
String[] prefixes = { "$", "?" };
String[] prefixes = {"$", "?"};

for (String prefix : prefixes) {

BindMarkers bindMarkers = BindMarkersFactory.indexed(prefix, 0).create();

BindMarker marker1 = bindMarkers.next();
Expand All @@ -76,9 +73,7 @@ void nextShouldIncrementBindMarker() {

@Test
void bindValueShouldBindByIndex() {

BindTarget bindTarget = mock();

BindMarkers bindMarkers = BindMarkersFactory.indexed("$", 0).create();

bindMarkers.next().bind(bindTarget, "foo");
Expand All @@ -91,7 +86,6 @@ void bindValueShouldBindByIndex() {
@Test
void bindNullShouldBindByIndex() {
BindTarget bindTarget = mock();

BindMarkers bindMarkers = BindMarkersFactory.indexed("$", 0).create();

bindMarkers.next(); // ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void shouldCreateNewBindMarkers() {
}

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

Expand Down

0 comments on commit 86650d1

Please sign in to comment.