diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java index f40d34ea99b..527da9d9b00 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.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. @@ -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)); } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java index 6d3c3367309..bfa6aa4be46 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java @@ -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)); } 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 fb7e6fa9e17..16b7a39be86 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 @@ -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 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) { 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 1c99636646c..e8134c1d369 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 @@ -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( 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 bf2dcd5ff6d..40ac7940094 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. @@ -34,30 +34,27 @@ public class MapConnectionFactoryLookupUnitTests { private static final String CONNECTION_FACTORY_NAME = "connectionFactory"; + @Test public void getConnectionFactoriesReturnsUnmodifiableMap() { MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup(); Map connectionFactories = lookup.getConnectionFactories(); - assertThatThrownBy(() -> connectionFactories.put("", - new DummyConnectionFactory())).isInstanceOf( - UnsupportedOperationException.class); + assertThatThrownBy(() -> connectionFactories.put("", 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); - - 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); } + } 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 5de63ceaa24..e6b0e09cb6d 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,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); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsUnitTests.java index c26ba5acb6c..83038dcc14a 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsUnitTests.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. @@ -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); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/IndexedBindMarkersUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/IndexedBindMarkersUnitTests.java index 9bc389d7188..e94b2cb512a 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/IndexedBindMarkersUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/IndexedBindMarkersUnitTests.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. @@ -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 diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/NamedBindMarkersUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/NamedBindMarkersUnitTests.java index d83691e5b2d..5c2f56d0890 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/NamedBindMarkersUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/NamedBindMarkersUnitTests.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. @@ -43,7 +43,7 @@ class NamedBindMarkersUnitTests { } @ParameterizedTest - @ValueSource(strings = { "$", "?" }) + @ValueSource(strings = {"$", "?"}) void nextShouldIncrementBindMarker(String prefix) { BindMarkers bindMarkers = BindMarkersFactory.named(prefix, "p", 32).create();