Polishing
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ 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));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -40,7 +40,7 @@ class DelegatingConnectionFactoryUnitTests {
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
void shouldDelegateGetConnection() {
|
||||
Mono<Connection> connectionMono = Mono.just(connectionMock);
|
||||
when(delegate.create()).thenReturn((Mono) connectionMono);
|
||||
@@ -53,6 +53,7 @@ class DelegatingConnectionFactoryUnitTests {
|
||||
assertThat(connectionFactory.unwrap()).isSameAs(delegate);
|
||||
}
|
||||
|
||||
|
||||
static class ExampleConnectionFactory extends DelegatingConnectionFactory {
|
||||
|
||||
ExampleConnectionFactory(ConnectionFactory targetConnectionFactory) {
|
||||
|
||||
@@ -64,8 +64,9 @@ class R2dbcTransactionManagerUnitTests {
|
||||
|
||||
private R2dbcTransactionManager tm;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
void before() {
|
||||
when(connectionFactoryMock.create()).thenReturn((Mono) Mono.just(connectionMock));
|
||||
when(connectionMock.beginTransaction()).thenReturn(Mono.empty());
|
||||
@@ -73,6 +74,7 @@ class R2dbcTransactionManagerUnitTests {
|
||||
tm = new R2dbcTransactionManager(connectionFactoryMock);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testSimpleTransaction() {
|
||||
TestTransactionSynchronization sync = new TestTransactionSynchronization(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -34,30 +34,27 @@ 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
|
||||
public void shouldLookupConnectionFactory() {
|
||||
Map<String, ConnectionFactory> connectionFactories = new HashMap<>();
|
||||
DummyConnectionFactory expectedConnectionFactory = new DummyConnectionFactory();
|
||||
|
||||
connectionFactories.put(CONNECTION_FACTORY_NAME, expectedConnectionFactory);
|
||||
MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup();
|
||||
|
||||
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
|
||||
@@ -68,27 +65,22 @@ public class MapConnectionFactoryLookupUnitTests {
|
||||
connectionFactories.put(CONNECTION_FACTORY_NAME, overriddenConnectionFactory);
|
||||
|
||||
MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup();
|
||||
|
||||
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());
|
||||
MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup(
|
||||
connectionFactories);
|
||||
MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup(connectionFactories);
|
||||
|
||||
assertThatThrownBy(
|
||||
() -> lookup.getConnectionFactory(CONNECTION_FACTORY_NAME)).isInstanceOf(
|
||||
ClassCastException.class);
|
||||
assertThatThrownBy(() -> lookup.getConnectionFactory(CONNECTION_FACTORY_NAME))
|
||||
.isInstanceOf(ClassCastException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,4 +91,5 @@ public class MapConnectionFactoryLookupUnitTests {
|
||||
() -> lookup.getConnectionFactory(CONNECTION_FACTORY_NAME)).isInstanceOf(
|
||||
ConnectionFactoryLookupFailureException.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,8 +77,9 @@ class DefaultDatabaseClientUnitTests {
|
||||
|
||||
private DatabaseClient.Builder databaseClientBuilder;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
void before() {
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
|
||||
@@ -89,6 +90,7 @@ class DefaultDatabaseClientUnitTests {
|
||||
connectionFactory).bindMarkers(BindMarkersFactory.indexed("$", 1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void connectionFactoryIsExposed() {
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -82,8 +82,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);
|
||||
@@ -94,8 +95,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(BindTarget.class);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -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(BindTarget.class);
|
||||
|
||||
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(BindTarget.class);
|
||||
|
||||
BindMarkers bindMarkers = BindMarkersFactory.indexed("$", 0).create();
|
||||
|
||||
bindMarkers.next().bind(bindTarget, "foo");
|
||||
@@ -91,7 +86,6 @@ class IndexedBindMarkersUnitTests {
|
||||
@Test
|
||||
void bindNullShouldBindByIndex() {
|
||||
BindTarget bindTarget = mock(BindTarget.class);
|
||||
|
||||
BindMarkers bindMarkers = BindMarkersFactory.indexed("$", 0).create();
|
||||
|
||||
bindMarkers.next(); // ignore
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -43,7 +43,7 @@ class NamedBindMarkersUnitTests {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = { "$", "?" })
|
||||
@ValueSource(strings = {"$", "?"})
|
||||
void nextShouldIncrementBindMarker(String prefix) {
|
||||
BindMarkers bindMarkers = BindMarkersFactory.named(prefix, "p", 32).create();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user