From 4b8adf2dccd37285e4b68e2796620be521844e2f Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 2 Jun 2023 23:28:14 +0200 Subject: [PATCH] Polishing --- .../AspectJAdviceParameterNameDiscoverer.java | 2 +- .../beans/TypeConverterSupport.java | 4 +- .../support/DefaultSingletonBeanRegistry.java | 4 +- .../support/DisposableBeanAdapter.java | 6 +-- .../support/AbstractApplicationContext.java | 4 +- .../annotation/configuration/ImportTests.java | 19 ++++++-- .../springframework/core/MethodParameter.java | 1 + .../ConnectionFactoryUtilsUnitTests.java | 4 +- .../DelegatingConnectionFactoryUnitTests.java | 3 +- .../R2dbcTransactionManagerUnitTests.java | 6 +-- .../SingleConnectionFactoryUnitTests.java | 10 ++-- ...nAwareConnectionFactoryProxyUnitTests.java | 2 + .../init/AbstractDatabasePopulatorTests.java | 47 +++++++++---------- .../init/CompositeDatabasePopulatorTests.java | 1 + .../H2DatabasePopulatorIntegrationTests.java | 6 +-- .../connection/init/ScriptUtilsUnitTests.java | 18 +++---- ...ractRoutingConnectionFactoryUnitTests.java | 20 ++++---- ...ctoryConnectionFactoryLookupUnitTests.java | 30 +++++------- .../lookup/DummyConnectionFactory.java | 6 +-- .../MapConnectionFactoryLookupUnitTests.java | 31 +++++------- ...bstractDatabaseClientIntegrationTests.java | 8 ++-- ...ctionalDatabaseClientIntegrationTests.java | 10 ++-- .../core/DefaultDatabaseClientUnitTests.java | 2 +- .../H2DatabaseClientIntegrationTests.java | 5 +- ...ctionalDatabaseClientIntegrationTests.java | 6 +-- .../BindMarkersFactoryResolverUnitTests.java | 10 +--- .../r2dbc/core/binding/BindingsUnitTests.java | 3 +- 27 files changed, 127 insertions(+), 141 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java index d7fc989d44f0..ec9b634ff89f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java @@ -302,7 +302,7 @@ public String[] getParameterNames(Constructor ctor) { } - private void bindParameterName(int index, String name) { + private void bindParameterName(int index, @Nullable String name) { this.parameterNameBindings[index] = name; this.numberOfRemainingUnboundArguments--; } diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java b/spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java index e99c875e5f09..c0ad9408e932 100644 --- a/spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 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. @@ -63,8 +63,8 @@ public T convertIfNecessary(@Nullable Object value, @Nullable Class requi (field != null ? new TypeDescriptor(field) : TypeDescriptor.valueOf(requiredType))); } - @Nullable @Override + @Nullable public T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable TypeDescriptor typeDescriptor) throws TypeMismatchException { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java index 0c16e50487d9..98ca29c7a43e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java @@ -102,7 +102,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements private boolean singletonsCurrentlyInDestruction = false; /** Disposable bean instances: bean name to disposable instance. */ - private final Map disposableBeans = new LinkedHashMap<>(); + private final Map disposableBeans = new LinkedHashMap<>(); /** Map between containing bean names: bean name to Set of bean names that the bean contains. */ private final Map> containedBeanMap = new ConcurrentHashMap<>(16); @@ -554,7 +554,7 @@ public void destroySingleton(String beanName) { // Destroy the corresponding DisposableBean instance. DisposableBean disposableBean; synchronized (this.disposableBeans) { - disposableBean = (DisposableBean) this.disposableBeans.remove(beanName); + disposableBean = this.disposableBeans.remove(beanName); } destroyBean(beanName, disposableBean); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java index c13d5c9600c2..0d2bc2adeb22 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java @@ -65,8 +65,8 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { private static final String SHUTDOWN_METHOD_NAME = "shutdown"; - private static final Log logger = LogFactory.getLog(DisposableBeanAdapter.class); + private static final Log logger = LogFactory.getLog(DisposableBeanAdapter.class); private final Object bean; @@ -240,7 +240,7 @@ else if (this.destroyMethods != null) { } } else if (this.destroyMethodNames != null) { - for (String destroyMethodName: this.destroyMethodNames) { + for (String destroyMethodName : this.destroyMethodNames) { Method destroyMethod = determineDestroyMethod(destroyMethodName); if (destroyMethod != null) { invokeCustomDestroyMethod( @@ -288,7 +288,7 @@ private Method findDestroyMethod(Class clazz, String name) { */ private void invokeCustomDestroyMethod(Method destroyMethod) { int paramCount = destroyMethod.getParameterCount(); - final Object[] args = new Object[paramCount]; + Object[] args = new Object[paramCount]; if (paramCount == 1) { args[0] = Boolean.TRUE; } diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index 871d166e5123..00bccae17b8d 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java @@ -463,7 +463,7 @@ ApplicationEventMulticaster getApplicationEventMulticaster() throws IllegalState @Override public void setApplicationStartup(ApplicationStartup applicationStartup) { - Assert.notNull(applicationStartup, "applicationStartup must not be null"); + Assert.notNull(applicationStartup, "ApplicationStartup must not be null"); this.applicationStartup = applicationStartup; } @@ -946,7 +946,6 @@ protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory b * onRefresh() method and publishing the * {@link org.springframework.context.event.ContextRefreshedEvent}. */ - @SuppressWarnings("deprecation") protected void finishRefresh() { // Clear context-level resource caches (such as ASM metadata from scanning). clearResourceCaches(); @@ -1047,7 +1046,6 @@ public void close() { * @see #close() * @see #registerShutdownHook() */ - @SuppressWarnings("deprecation") protected void doClose() { // Check whether an actual close attempt is necessary... if (this.active.get() && this.closed.compareAndSet(false, true)) { diff --git a/spring-context/src/test/java/org/springframework/context/annotation/configuration/ImportTests.java b/spring-context/src/test/java/org/springframework/context/annotation/configuration/ImportTests.java index 0056376f5553..04638e1822e5 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/configuration/ImportTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/configuration/ImportTests.java @@ -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. @@ -41,6 +41,7 @@ class ImportTests { private DefaultListableBeanFactory processConfigurationClasses(Class... classes) { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); + beanFactory.setAllowBeanDefinitionOverriding(false); for (Class clazz : classes) { beanFactory.registerBeanDefinition(clazz.getSimpleName(), new RootBeanDefinition(clazz)); } @@ -56,9 +57,10 @@ private void assertBeanDefinitionCount(int expectedCount, Class... classes) { for (Class clazz : classes) { beanFactory.getBean(clazz); } - } + // ------------------------------------------------------------------------ + @Test void testProcessImportsWithAsm() { int configClasses = 2; @@ -158,6 +160,13 @@ void testImportAnnotationWithThreeLevelRecursion() { assertBeanDefinitionCount(configClasses + beansInClasses, FirstLevel.class); } + @Test + void testImportAnnotationWithThreeLevelRecursionAndDoubleImport() { + int configClasses = 5; + int beansInClasses = 5; + assertBeanDefinitionCount(configClasses + beansInClasses, FirstLevel.class, FirstLevelPlus.class); + } + // ------------------------------------------------------------------------ @Test @@ -167,7 +176,6 @@ void testImportAnnotationWithMultipleArguments() { assertBeanDefinitionCount((configClasses + beansInClasses), WithMultipleArgumentsToImportAnnotation.class); } - @Test void testImportAnnotationWithMultipleArgumentsResultingInOverriddenBeanDefinition() { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @@ -245,6 +253,11 @@ TestBean m() { } } + @Configuration + @Import(ThirdLevel.class) + static class FirstLevelPlus { + } + @Configuration @Import({ThirdLevel.class, InitBean.class}) static class SecondLevel { diff --git a/spring-core/src/main/java/org/springframework/core/MethodParameter.java b/spring-core/src/main/java/org/springframework/core/MethodParameter.java index 556005cf3dca..8004b87a2f92 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -780,6 +780,7 @@ public MethodParameter clone() { return new MethodParameter(this); } + /** * Create a new MethodParameter for the given method or constructor. *

This is a convenience factory method for scenarios where a diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/ConnectionFactoryUtilsUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/ConnectionFactoryUtilsUnitTests.java index 3362e0c1fe0b..9292f11dd377 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/ConnectionFactoryUtilsUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/ConnectionFactoryUtilsUnitTests.java @@ -75,7 +75,7 @@ public void shouldTranslateTimeoutException() { @Test public void shouldNotTranslateUnknownExceptions() { Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "", - new MyTransientExceptions()); + new MyTransientException()); assertThat(exception).isExactlyInstanceOf(UncategorizedR2dbcException.class); } @@ -153,7 +153,7 @@ public void messageGenerationNullMessage() { @SuppressWarnings("serial") - private static class MyTransientExceptions extends R2dbcException { + private static class MyTransientException extends R2dbcException { } } diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryUnitTests.java index faba0369ea76..d02c0ffa66eb 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryUnitTests.java @@ -40,7 +40,7 @@ class DelegatingConnectionFactoryUnitTests { @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) void shouldDelegateGetConnection() { Mono connectionMono = Mono.just(connectionMock); when(delegate.create()).thenReturn((Mono) connectionMono); @@ -53,6 +53,7 @@ void shouldDelegateUnwrapWithoutImplementing() { assertThat(connectionFactory.unwrap()).isSameAs(delegate); } + static class ExampleConnectionFactory extends DelegatingConnectionFactory { ExampleConnectionFactory(ConnectionFactory targetConnectionFactory) { diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerUnitTests.java index 9e222589b1e5..857744d828b6 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerUnitTests.java @@ -65,6 +65,7 @@ class R2dbcTransactionManagerUnitTests { private R2dbcTransactionManager tm; + @BeforeEach @SuppressWarnings({ "unchecked", "rawtypes" }) void before() { @@ -74,6 +75,7 @@ void before() { tm = new R2dbcTransactionManager(connectionFactoryMock); } + @Test void testSimpleTransaction() { TestTransactionSynchronization sync = new TestTransactionSynchronization( @@ -445,8 +447,7 @@ void testPropagationSupportsAndRequiresNew() { } - private static class TestTransactionSynchronization - implements TransactionSynchronization { + private static class TestTransactionSynchronization implements TransactionSynchronization { private int status; @@ -519,7 +520,6 @@ protected void doAfterCompletion(int status) { this.afterCompletionCalled = true; assertThat(status).isEqualTo(this.status); } - } } diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryUnitTests.java index 9bc4a9582fc4..dec679b76498 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryUnitTests.java @@ -48,8 +48,8 @@ void shouldAllocateSameConnection() { Connection c1 = cf1.block(); Connection c2 = cf2.block(); - assertThat(c1).isSameAs(c2); + factory.destroy(); } @@ -63,7 +63,6 @@ void shouldApplyAutoCommit() { .verifyComplete(); factory.setAutoCommit(true); - factory.create().as(StepVerifier::create) .consumeNextWith(actual -> assertThat(actual.isAutoCommit()).isTrue()) .verifyComplete(); @@ -75,7 +74,6 @@ void shouldApplyAutoCommit() { @SuppressWarnings("rawtypes") void shouldSuppressClose() { SingleConnectionFactory factory = new SingleConnectionFactory("r2dbc:h2:mem:///foo", true); - Connection connection = factory.create().block(); StepVerifier.create(connection.close()).verifyComplete(); @@ -85,19 +83,19 @@ void shouldSuppressClose() { StepVerifier.create( connection.setTransactionIsolationLevel(IsolationLevel.READ_COMMITTED)) .verifyComplete(); + factory.destroy(); } @Test void shouldNotSuppressClose() { SingleConnectionFactory factory = new SingleConnectionFactory("r2dbc:h2:mem:///foo", false); - Connection connection = factory.create().block(); StepVerifier.create(connection.close()).verifyComplete(); - StepVerifier.create(connection.setTransactionIsolationLevel(IsolationLevel.READ_COMMITTED)) .verifyError(R2dbcNonTransientResourceException.class); + factory.destroy(); } @@ -107,7 +105,6 @@ void releaseConnectionShouldNotCloseConnection() { ConnectionFactoryMetadata metadata = mock(); SingleConnectionFactory factory = new SingleConnectionFactory(connectionMock, metadata, true); - Connection connection = factory.create().block(); ConnectionFactoryUtils.releaseConnection(connection, factory) @@ -125,7 +122,6 @@ void releaseConnectionShouldCloseUnrelatedConnection() { when(otherConnection.close()).thenReturn(Mono.empty()); SingleConnectionFactory factory = new SingleConnectionFactory(connectionMock, metadata, false); - factory.create().as(StepVerifier::create).expectNextCount(1).verifyComplete(); ConnectionFactoryUtils.releaseConnection(otherConnection, factory) diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java index 9344bb42bb6c..8dd4794d39be 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java @@ -55,6 +55,7 @@ class TransactionAwareConnectionFactoryProxyUnitTests { R2dbcTransactionManager tm; + @BeforeEach @SuppressWarnings({ "rawtypes", "unchecked" }) void before() { @@ -63,6 +64,7 @@ void before() { tm = new R2dbcTransactionManager(connectionFactoryMock); } + @Test void createShouldWrapConnection() { new TransactionAwareConnectionFactoryProxy(connectionFactoryMock).create() diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/AbstractDatabasePopulatorTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/AbstractDatabasePopulatorTests.java index fe281681b53d..ce7eb16590d6 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/AbstractDatabasePopulatorTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/AbstractDatabasePopulatorTests.java @@ -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. @@ -46,23 +46,15 @@ void scriptWithSingleLineCommentsAndFailedDrop() { databasePopulator.setIgnoreFailedDrops(true); runPopulator(); - assertUsersDatabaseCreated("Heisenberg"); } - private void runPopulator() { - databasePopulator.populate(getConnectionFactory()) // - .as(StepVerifier::create) // - .verifyComplete(); - } - @Test void scriptWithStandardEscapedLiteral() { databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(resource("db-test-data-escaped-literal.sql")); runPopulator(); - assertUsersDatabaseCreated("'Heisenberg'"); } @@ -72,7 +64,6 @@ void scriptWithMySqlEscapedLiteral() { databasePopulator.addScript(resource("db-test-data-mysql-escaped-literal.sql")); runPopulator(); - assertUsersDatabaseCreated("\\$Heisenberg\\$"); } @@ -82,7 +73,6 @@ void scriptWithMultipleStatements() { databasePopulator.addScript(resource("db-test-data-multiple.sql")); runPopulator(); - assertUsersDatabaseCreated("Heisenberg", "Jesse"); } @@ -93,31 +83,21 @@ void scriptWithMultipleStatementsAndLongSeparator() { databasePopulator.setSeparator("@@"); runPopulator(); - assertUsersDatabaseCreated("Heisenberg", "Jesse"); } - abstract ConnectionFactory getConnectionFactory(); - - Resource resource(String path) { - return resourceLoader.getResource(path); - } - Resource defaultSchema() { - return resource("db-schema.sql"); - } - - Resource usersSchema() { - return resource("users-schema.sql"); + private void runPopulator() { + databasePopulator.populate(getConnectionFactory()) // + .as(StepVerifier::create) // + .verifyComplete(); } void assertUsersDatabaseCreated(String... lastNames) { assertUsersDatabaseCreated(getConnectionFactory(), lastNames); } - void assertUsersDatabaseCreated(ConnectionFactory connectionFactory, - String... lastNames) { - + void assertUsersDatabaseCreated(ConnectionFactory connectionFactory,String... lastNames) { DatabaseClient client = DatabaseClient.create(connectionFactory); for (String lastName : lastNames) { @@ -132,4 +112,19 @@ void assertUsersDatabaseCreated(ConnectionFactory connectionFactory, } } + + abstract ConnectionFactory getConnectionFactory(); + + Resource resource(String path) { + return resourceLoader.getResource(path); + } + + Resource defaultSchema() { + return resource("db-schema.sql"); + } + + Resource usersSchema() { + return resource("users-schema.sql"); + } + } diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/CompositeDatabasePopulatorTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/CompositeDatabasePopulatorTests.java index c149eb4a777e..5f68223318d3 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/CompositeDatabasePopulatorTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/CompositeDatabasePopulatorTests.java @@ -52,6 +52,7 @@ void before() { when(mockedDatabasePopulator2.populate(mockedConnection)).thenReturn(Mono.empty()); } + @Test void addPopulators() { CompositeDatabasePopulator populator = new CompositeDatabasePopulator(); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/H2DatabasePopulatorIntegrationTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/H2DatabasePopulatorIntegrationTests.java index e11cbe95cb21..d34f7fcf045c 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/H2DatabasePopulatorIntegrationTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/H2DatabasePopulatorIntegrationTests.java @@ -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. @@ -30,8 +30,8 @@ class H2DatabasePopulatorIntegrationTests extends AbstractDatabasePopulatorTests UUID databaseName = UUID.randomUUID(); - ConnectionFactory connectionFactory = ConnectionFactories.get("r2dbc:h2:mem:///" - + databaseName + "?options=DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"); + ConnectionFactory connectionFactory = ConnectionFactories.get( + "r2dbc:h2:mem:///" + databaseName + "?options=DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"); @Override diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ScriptUtilsUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ScriptUtilsUnitTests.java index 63fe4ecd96c1..41dd48477d99 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ScriptUtilsUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ScriptUtilsUnitTests.java @@ -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. @@ -43,7 +43,6 @@ * @author Nicolas Debeissat * @author Mark Paluch * @since 5.3 - * @see ScriptUtilsIntegrationTests */ public class ScriptUtilsUnitTests { @@ -133,8 +132,8 @@ public void readAndSplitScriptContainingCommentsWithMultiplePrefixes() throws Ex } private void splitScriptContainingComments(String script, String... commentPrefixes) { - List statements = ScriptUtils.splitSqlScript(null, script, ";", commentPrefixes, DEFAULT_BLOCK_COMMENT_START_DELIMITER, - DEFAULT_BLOCK_COMMENT_END_DELIMITER); + List statements = ScriptUtils.splitSqlScript(null, script, ";", commentPrefixes, + DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER); String statement1 = "insert into customer (id, name) values (1, 'Rod; Johnson'), (2, 'Adrian Collier')"; String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)"; @@ -218,20 +217,21 @@ public void readAndSplitScriptContainingMultiLineNestedComments() throws Excepti ~/* double \\" quotes */\n insert into colors(color_num) values(42);~ | ; | true """) public void containsStatementSeparator(String script, String delimiter, boolean expected) { - boolean contains = ScriptUtils.containsStatementSeparator(null, script, delimiter, DEFAULT_COMMENT_PREFIXES, - DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER); + boolean contains = ScriptUtils.containsStatementSeparator(null, script, delimiter, + DEFAULT_COMMENT_PREFIXES, DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER); assertThat(contains).isEqualTo(expected); } - private String readScript(String path) throws Exception { + + private String readScript(String path) { EncodedResource resource = new EncodedResource(new ClassPathResource(path, getClass())); return ScriptUtils.readScript(resource, DefaultDataBufferFactory.sharedInstance, DEFAULT_STATEMENT_SEPARATOR).block(); } private static List splitSqlScript(String script, String separator) throws ScriptException { - return ScriptUtils.splitSqlScript(null, script, separator, DEFAULT_COMMENT_PREFIXES, DEFAULT_BLOCK_COMMENT_START_DELIMITER, - DEFAULT_BLOCK_COMMENT_END_DELIMITER); + return ScriptUtils.splitSqlScript(null, script, separator, DEFAULT_COMMENT_PREFIXES, + DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER); } } diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactoryUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactoryUnitTests.java index 43ea3141a140..ecadb882327b 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactoryUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactoryUnitTests.java @@ -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. @@ -48,15 +48,16 @@ public class AbstractRoutingConnectionFactoryUnitTests { DummyRoutingConnectionFactory connectionFactory; + @BeforeEach public void before() { connectionFactory = new DummyRoutingConnectionFactory(); connectionFactory.setDefaultTargetConnectionFactory(defaultConnectionFactory); } + @Test public void shouldDetermineRoutedFactory() { - connectionFactory.setTargetConnectionFactories( singletonMap("key", routedConnectionFactory)); connectionFactory.setConnectionFactoryLookup(new MapConnectionFactoryLookup()); @@ -85,8 +86,8 @@ public void shouldFallbackToDefaultConnectionFactory() { public void initializationShouldFailUnsupportedLookupKey() { connectionFactory.setTargetConnectionFactories(singletonMap("key", new Object())); - assertThatThrownBy(() -> connectionFactory.afterPropertiesSet()).isInstanceOf( - IllegalArgumentException.class); + assertThatThrownBy(() -> connectionFactory.afterPropertiesSet()) + .isInstanceOf(IllegalArgumentException.class); } @Test @@ -96,8 +97,7 @@ public void initializationShouldFailUnresolvableKey() { assertThatThrownBy(() -> connectionFactory.afterPropertiesSet()) .isInstanceOf(ConnectionFactoryLookupFailureException.class) - .hasMessageContaining( - "No ConnectionFactory with name 'value' registered"); + .hasMessageContaining("No ConnectionFactory with name 'value' registered"); } @Test @@ -144,12 +144,11 @@ public void connectionFactoryRetrievalWithoutLookupKeyShouldReturnDefaultConnect @Test public void shouldLookupFromMap() { - MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup("lookup-key", - routedConnectionFactory); + MapConnectionFactoryLookup lookup = + new MapConnectionFactoryLookup("lookup-key", routedConnectionFactory); connectionFactory.setConnectionFactoryLookup(lookup); - connectionFactory.setTargetConnectionFactories( - singletonMap("my-key", "lookup-key")); + connectionFactory.setTargetConnectionFactories(singletonMap("my-key", "lookup-key")); connectionFactory.afterPropertiesSet(); connectionFactory.determineTargetConnectionFactory() @@ -183,6 +182,7 @@ public void shouldAllowModificationsAfterInitialization() { .verifyComplete(); } + static class DummyRoutingConnectionFactory extends AbstractRoutingConnectionFactory { @Override diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/BeanFactoryConnectionFactoryLookupUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/BeanFactoryConnectionFactoryLookupUnitTests.java index 174447796ae1..2ccb13cb977c 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/BeanFactoryConnectionFactoryLookupUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/BeanFactoryConnectionFactoryLookupUnitTests.java @@ -44,18 +44,17 @@ public class BeanFactoryConnectionFactoryLookupUnitTests { @Mock BeanFactory beanFactory; + @Test public void shouldLookupConnectionFactory() { DummyConnectionFactory expectedConnectionFactory = new DummyConnectionFactory(); - when(beanFactory.getBean(CONNECTION_FACTORY_BEAN_NAME, - ConnectionFactory.class)).thenReturn(expectedConnectionFactory); + when(beanFactory.getBean(CONNECTION_FACTORY_BEAN_NAME, ConnectionFactory.class)) + .thenReturn(expectedConnectionFactory); BeanFactoryConnectionFactoryLookup lookup = new BeanFactoryConnectionFactoryLookup(); lookup.setBeanFactory(beanFactory); - ConnectionFactory connectionFactory = lookup.getConnectionFactory( - CONNECTION_FACTORY_BEAN_NAME); - + ConnectionFactory connectionFactory = lookup.getConnectionFactory(CONNECTION_FACTORY_BEAN_NAME); assertThat(connectionFactory).isNotNull(); assertThat(connectionFactory).isSameAs(expectedConnectionFactory); } @@ -63,26 +62,21 @@ public void shouldLookupConnectionFactory() { @Test public void shouldLookupWhereBeanFactoryYieldsNonConnectionFactoryType() { BeanFactory beanFactory = mock(); + when(beanFactory.getBean(CONNECTION_FACTORY_BEAN_NAME, ConnectionFactory.class)) + .thenThrow(new BeanNotOfRequiredTypeException( + CONNECTION_FACTORY_BEAN_NAME, ConnectionFactory.class, String.class)); - when(beanFactory.getBean(CONNECTION_FACTORY_BEAN_NAME, - ConnectionFactory.class)).thenThrow( - new BeanNotOfRequiredTypeException(CONNECTION_FACTORY_BEAN_NAME, - ConnectionFactory.class, String.class)); - - BeanFactoryConnectionFactoryLookup lookup = new BeanFactoryConnectionFactoryLookup( - beanFactory); - - assertThatExceptionOfType( - ConnectionFactoryLookupFailureException.class).isThrownBy( - () -> lookup.getConnectionFactory(CONNECTION_FACTORY_BEAN_NAME)); + BeanFactoryConnectionFactoryLookup lookup = new BeanFactoryConnectionFactoryLookup(beanFactory); + assertThatExceptionOfType(ConnectionFactoryLookupFailureException.class) + .isThrownBy(() -> lookup.getConnectionFactory(CONNECTION_FACTORY_BEAN_NAME)); } @Test public void shouldLookupWhereBeanFactoryHasNotBeenSupplied() { BeanFactoryConnectionFactoryLookup lookup = new BeanFactoryConnectionFactoryLookup(); - assertThatThrownBy(() -> lookup.getConnectionFactory( - CONNECTION_FACTORY_BEAN_NAME)).isInstanceOf(IllegalStateException.class); + assertThatThrownBy(() -> lookup.getConnectionFactory(CONNECTION_FACTORY_BEAN_NAME)) + .isInstanceOf(IllegalStateException.class); } } diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/DummyConnectionFactory.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/DummyConnectionFactory.java index 1d3b8a849b1b..b2f1229cf617 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/DummyConnectionFactory.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/DummyConnectionFactory.java @@ -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. @@ -23,8 +23,8 @@ /** * Stub, do-nothing {@link ConnectionFactory} implementation. - *

- * All methods throw {@link UnsupportedOperationException}. + * + *

All methods throw {@link UnsupportedOperationException}. * * @author Mark Paluch */ diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/MapConnectionFactoryLookupUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/MapConnectionFactoryLookupUnitTests.java index bf2dcd5ff6dc..89815b71c2f8 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/MapConnectionFactoryLookupUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/MapConnectionFactoryLookupUnitTests.java @@ -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,23 +40,19 @@ public void getConnectionFactoriesReturnsUnmodifiableMap() { Map connectionFactories = lookup.getConnectionFactories(); assertThatThrownBy(() -> connectionFactories.put("", - new DummyConnectionFactory())).isInstanceOf( - UnsupportedOperationException.class); + new DummyConnectionFactory())).isInstanceOf(UnsupportedOperationException.class); } @Test public void shouldLookupConnectionFactory() { Map 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); - + ConnectionFactory connectionFactory = lookup.getConnectionFactory(CONNECTION_FACTORY_NAME); assertThat(connectionFactory).isNotNull().isSameAs(expectedConnectionFactory); } @@ -68,13 +64,10 @@ public void addingConnectionFactoryPermitsOverride() { 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); - + ConnectionFactory connectionFactory = lookup.getConnectionFactory(CONNECTION_FACTORY_NAME); assertThat(connectionFactory).isNotNull().isSameAs(expectedConnectionFactory); } @@ -83,20 +76,18 @@ public void addingConnectionFactoryPermitsOverride() { 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 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); } + } diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/AbstractDatabaseClientIntegrationTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/AbstractDatabaseClientIntegrationTests.java index 63844c103aae..e18ed9895284 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/AbstractDatabaseClientIntegrationTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/AbstractDatabaseClientIntegrationTests.java @@ -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. @@ -38,6 +38,7 @@ public abstract class AbstractDatabaseClientIntegrationTests { private ConnectionFactory connectionFactory; + @BeforeEach public void before() { connectionFactory = createConnectionFactory(); @@ -52,8 +53,7 @@ public void before() { } /** - * Creates a {@link ConnectionFactory} to be used in this test. - * + * Create a {@link ConnectionFactory} to be used in this test. * @return the {@link ConnectionFactory} to be used in this test */ protected abstract ConnectionFactory createConnectionFactory(); @@ -66,11 +66,11 @@ public void before() { *

  • name varchar(255), nullable
  • *
  • manual integer, nullable
  • * - * * @return the CREATE TABLE statement for table {@code legoset} with three columns. */ protected abstract String getCreateTableStatement(); + @Test public void executeInsert() { DatabaseClient databaseClient = DatabaseClient.create(connectionFactory); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/AbstractTransactionalDatabaseClientIntegrationTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/AbstractTransactionalDatabaseClientIntegrationTests.java index 13831337cff0..081ec90ab378 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/AbstractTransactionalDatabaseClientIntegrationTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/AbstractTransactionalDatabaseClientIntegrationTests.java @@ -51,12 +51,14 @@ public abstract class AbstractTransactionalDatabaseClientIntegrationTests { AnnotationConfigApplicationContext context; DatabaseClient databaseClient; + R2dbcTransactionManager transactionManager; + TransactionalOperator rxtx; + @BeforeEach public void before() { - connectionFactory = createConnectionFactory(); context = new AnnotationConfigApplicationContext(); @@ -64,7 +66,6 @@ public void before() { context.register(Config.class); context.refresh(); - Mono.from(connectionFactory.create()) .flatMapMany(connection -> Flux.from(connection.createStatement("DROP TABLE legoset").execute()) .flatMap(Result::getRowsUpdated) @@ -82,6 +83,7 @@ public void tearDown() { context.close(); } + /** * Create a {@link ConnectionFactory} to be used in this test. * @return the {@link ConnectionFactory} to be used in this test. @@ -107,6 +109,7 @@ protected String getInsertIntoLegosetStatement() { return "INSERT INTO legoset (id, name, manual) VALUES(:id, :name, :manual)"; } + @Test public void executeInsertInTransaction() { Flux longFlux = databaseClient @@ -131,7 +134,6 @@ public void executeInsertInTransaction() { @Test public void shouldRollbackTransaction() { - Mono integerFlux = databaseClient.sql(getInsertIntoLegosetStatement()) .bind(0, 42055) .bind(1, "SCHAUFELRADBAGGER") @@ -154,7 +156,6 @@ public void shouldRollbackTransaction() { @Test public void shouldRollbackTransactionUsingTransactionalOperator() { - DatabaseClient databaseClient = DatabaseClient.create(connectionFactory); TransactionalOperator transactionalOperator = TransactionalOperator @@ -202,7 +203,6 @@ ReactiveTransactionManager txMgr(ConnectionFactory connectionFactory) { TransactionalOperator transactionalOperator(ReactiveTransactionManager transactionManager) { return TransactionalOperator.create(transactionManager); } - } } diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientUnitTests.java index a6c608cbbd94..8ebf0f1a83ae 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientUnitTests.java @@ -77,7 +77,7 @@ class DefaultDatabaseClientUnitTests { @BeforeEach - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) void before() { ConnectionFactory connectionFactory = mock(); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/H2DatabaseClientIntegrationTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/H2DatabaseClientIntegrationTests.java index 7bf3f3883cbf..e808e5e1aaee 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/H2DatabaseClientIntegrationTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/H2DatabaseClientIntegrationTests.java @@ -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. @@ -24,8 +24,7 @@ * * @author Mark Paluch */ -public class H2DatabaseClientIntegrationTests - extends AbstractDatabaseClientIntegrationTests { +public class H2DatabaseClientIntegrationTests extends AbstractDatabaseClientIntegrationTests { public static String CREATE_TABLE_LEGOSET = "CREATE TABLE legoset (\n" // + " id serial CONSTRAINT id PRIMARY KEY,\n" // diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/H2TransactionalDatabaseClientIntegrationTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/H2TransactionalDatabaseClientIntegrationTests.java index e326f851ab1e..b179f677a4e4 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/H2TransactionalDatabaseClientIntegrationTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/H2TransactionalDatabaseClientIntegrationTests.java @@ -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. @@ -24,8 +24,7 @@ * * @author Mark Paluch */ -public class H2TransactionalDatabaseClientIntegrationTests - extends AbstractTransactionalDatabaseClientIntegrationTests { +public class H2TransactionalDatabaseClientIntegrationTests extends AbstractTransactionalDatabaseClientIntegrationTests { public static String CREATE_TABLE_LEGOSET = "CREATE TABLE legoset (\n" // + " id integer CONSTRAINT id PRIMARY KEY,\n" // @@ -43,4 +42,5 @@ protected ConnectionFactory createConnectionFactory() { protected String getCreateTableStatement() { return CREATE_TABLE_LEGOSET; } + } diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/BindMarkersFactoryResolverUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/BindMarkersFactoryResolverUnitTests.java index 2314b782b7ea..85fb67bbb5c8 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/BindMarkersFactoryResolverUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/BindMarkersFactoryResolverUnitTests.java @@ -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. @@ -33,7 +33,6 @@ class BindMarkersFactoryResolverUnitTests { @Test void shouldReturnBindMarkersFactoryForH2() { - BindMarkers bindMarkers = BindMarkersFactoryResolver .resolve(new MockConnectionFactory("H2")).create(); @@ -42,7 +41,6 @@ void shouldReturnBindMarkersFactoryForH2() { @Test void shouldReturnBindMarkersFactoryForMariaDB() { - BindMarkers bindMarkers = BindMarkersFactoryResolver .resolve(new MockConnectionFactory("MariaDB")).create(); @@ -51,7 +49,6 @@ void shouldReturnBindMarkersFactoryForMariaDB() { @Test void shouldReturnBindMarkersFactoryForMicrosoftSQLServer() { - BindMarkers bindMarkers = BindMarkersFactoryResolver .resolve(new MockConnectionFactory("Microsoft SQL Server")).create(); @@ -60,7 +57,6 @@ void shouldReturnBindMarkersFactoryForMicrosoftSQLServer() { @Test void shouldReturnBindMarkersFactoryForMySQL() { - BindMarkers bindMarkers = BindMarkersFactoryResolver .resolve(new MockConnectionFactory("MySQL")).create(); @@ -69,7 +65,6 @@ void shouldReturnBindMarkersFactoryForMySQL() { @Test void shouldReturnBindMarkersFactoryForOracle() { - BindMarkers bindMarkers = BindMarkersFactoryResolver .resolve(new MockConnectionFactory("Oracle Database")).create(); @@ -78,13 +73,13 @@ void shouldReturnBindMarkersFactoryForOracle() { @Test void shouldReturnBindMarkersFactoryForPostgreSQL() { - BindMarkers bindMarkers = BindMarkersFactoryResolver .resolve(new MockConnectionFactory("PostgreSQL")).create(); assertThat(bindMarkers.next().getPlaceholder()).isEqualTo("$1"); } + static class MockConnectionFactory implements ConnectionFactory { private final String driverName; @@ -102,7 +97,6 @@ public Publisher create() { public ConnectionFactoryMetadata getMetadata() { return () -> driverName; } - } } diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/BindingsUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/BindingsUnitTests.java index 95bddc7535d0..a5daced20ea6 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/BindingsUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/BindingsUnitTests.java @@ -26,7 +26,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; - /** * Unit tests for {@link Bindings}. * @@ -35,8 +34,10 @@ class BindingsUnitTests { BindMarkersFactory markersFactory = BindMarkersFactory.indexed("$", 1); + BindTarget bindTarget = mock(); + @Test void shouldCreateBindings() { MutableBindings bindings = new MutableBindings(markersFactory.create());