Polish contribution
See gh-31248
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.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.jdbc.datasource.lookup;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@@ -28,7 +27,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
|
||||
/**
|
||||
* Tests for {@link AbstractRoutingDataSource}.
|
||||
*
|
||||
@@ -38,7 +36,7 @@ class AbstractRoutingDataSourceTests {
|
||||
|
||||
@Test
|
||||
void setTargetDataSources() {
|
||||
final ThreadLocal<String> lookupKey = new ThreadLocal<>();
|
||||
ThreadLocal<String> lookupKey = new ThreadLocal<>();
|
||||
AbstractRoutingDataSource routingDataSource = new AbstractRoutingDataSource() {
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
@@ -50,14 +48,11 @@ class AbstractRoutingDataSourceTests {
|
||||
|
||||
MapDataSourceLookup dataSourceLookup = new MapDataSourceLookup();
|
||||
dataSourceLookup.addDataSource("dataSource2", ds2);
|
||||
|
||||
routingDataSource.setDataSourceLookup(dataSourceLookup);
|
||||
|
||||
Map<Object, Object> targetDataSources = new HashMap<>();
|
||||
targetDataSources.put("ds1", ds1);
|
||||
targetDataSources.put("ds2", "dataSource2");
|
||||
routingDataSource.setTargetDataSources(targetDataSources);
|
||||
|
||||
routingDataSource.setTargetDataSources(Map.of("ds1", ds1, "ds2", "dataSource2"));
|
||||
routingDataSource.afterPropertiesSet();
|
||||
|
||||
lookupKey.set("ds1");
|
||||
assertThat(routingDataSource.determineTargetDataSource()).isSameAs(ds1);
|
||||
lookupKey.set("ds2");
|
||||
@@ -84,9 +79,7 @@ class AbstractRoutingDataSourceTests {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Map<Object, Object> targetDataSources = new HashMap<>();
|
||||
targetDataSources.put("ds1", 1);
|
||||
routingDataSource.setTargetDataSources(targetDataSources);
|
||||
routingDataSource.setTargetDataSources(Map.of("ds1", 1));
|
||||
assertThatIllegalArgumentException().isThrownBy(routingDataSource::afterPropertiesSet)
|
||||
.withMessage("Illegal data source value - only [javax.sql.DataSource] and String supported: 1");
|
||||
}
|
||||
@@ -94,7 +87,7 @@ class AbstractRoutingDataSourceTests {
|
||||
|
||||
@Test
|
||||
void setDefaultTargetDataSource() {
|
||||
final ThreadLocal<String> lookupKey = new ThreadLocal<>();
|
||||
ThreadLocal<String> lookupKey = new ThreadLocal<>();
|
||||
AbstractRoutingDataSource routingDataSource = new AbstractRoutingDataSource() {
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
@@ -102,7 +95,7 @@ class AbstractRoutingDataSourceTests {
|
||||
}
|
||||
};
|
||||
DataSource ds = new StubDataSource();
|
||||
routingDataSource.setTargetDataSources(new HashMap<>());
|
||||
routingDataSource.setTargetDataSources(Map.of());
|
||||
routingDataSource.setDefaultTargetDataSource(ds);
|
||||
routingDataSource.afterPropertiesSet();
|
||||
lookupKey.set("foo");
|
||||
@@ -111,7 +104,7 @@ class AbstractRoutingDataSourceTests {
|
||||
|
||||
@Test
|
||||
void setDefaultTargetDataSourceFallbackIsFalse() {
|
||||
final ThreadLocal<String> lookupKey = new ThreadLocal<>();
|
||||
ThreadLocal<String> lookupKey = new ThreadLocal<>();
|
||||
AbstractRoutingDataSource routingDataSource = new AbstractRoutingDataSource() {
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
@@ -119,7 +112,7 @@ class AbstractRoutingDataSourceTests {
|
||||
}
|
||||
};
|
||||
DataSource ds = new StubDataSource();
|
||||
routingDataSource.setTargetDataSources(new HashMap<>());
|
||||
routingDataSource.setTargetDataSources(Map.of());
|
||||
routingDataSource.setDefaultTargetDataSource(ds);
|
||||
routingDataSource.setLenientFallback(false);
|
||||
routingDataSource.afterPropertiesSet();
|
||||
@@ -130,7 +123,7 @@ class AbstractRoutingDataSourceTests {
|
||||
|
||||
@Test
|
||||
void setDefaultTargetDataSourceLookupKeyIsNullWhenFallbackIsFalse() {
|
||||
final ThreadLocal<String> lookupKey = new ThreadLocal<>();
|
||||
ThreadLocal<String> lookupKey = new ThreadLocal<>();
|
||||
AbstractRoutingDataSource routingDataSource = new AbstractRoutingDataSource() {
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
@@ -138,7 +131,7 @@ class AbstractRoutingDataSourceTests {
|
||||
}
|
||||
};
|
||||
DataSource ds = new StubDataSource();
|
||||
routingDataSource.setTargetDataSources(new HashMap<>());
|
||||
routingDataSource.setTargetDataSources(Map.of());
|
||||
routingDataSource.setDefaultTargetDataSource(ds);
|
||||
routingDataSource.setLenientFallback(false);
|
||||
routingDataSource.afterPropertiesSet();
|
||||
@@ -147,7 +140,7 @@ class AbstractRoutingDataSourceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInitialize_synchronizeTargetDataSourcesToResolvedDataSources() {
|
||||
void initializeSynchronizesTargetDataSourcesToResolvedDataSources() {
|
||||
AbstractRoutingDataSource routingDataSource = new AbstractRoutingDataSource() {
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
@@ -158,11 +151,7 @@ class AbstractRoutingDataSourceTests {
|
||||
DataSource ds1 = new StubDataSource();
|
||||
DataSource ds2 = new StubDataSource();
|
||||
|
||||
Map<Object, Object> targetDataSources = new HashMap<>();
|
||||
targetDataSources.put("ds1", ds1);
|
||||
targetDataSources.put("ds2", ds2);
|
||||
routingDataSource.setTargetDataSources(targetDataSources);
|
||||
|
||||
routingDataSource.setTargetDataSources(Map.of("ds1", ds1, "ds2", ds2));
|
||||
routingDataSource.initialize();
|
||||
|
||||
Map<Object, DataSource> resolvedDataSources = routingDataSource.getResolvedDataSources();
|
||||
|
||||
Reference in New Issue
Block a user