Polishing

This commit is contained in:
Sam Brannen 2024-02-16 11:40:38 +01:00
parent fc9a118406
commit b6df5a677e
8 changed files with 69 additions and 70 deletions

View File

@ -17,7 +17,7 @@
package org.springframework.jdbc.datasource.embedded;
/**
* A {@link EmbeddedDatabaseConfigurer} delegate that can be used to customize
* An {@link EmbeddedDatabaseConfigurer} delegate that can be used to customize
* the embedded database.
*
* @author Stephane Nicoll

View File

@ -53,8 +53,8 @@ public abstract class EmbeddedDatabaseConfigurers {
}
/**
* Customize the default configurer for the given embedded database type. The
* {@code customizer} operator typically uses
* Customize the default configurer for the given embedded database type.
* <p>The {@code customizer} typically uses
* {@link EmbeddedDatabaseConfigurerDelegate} to customize things as necessary.
* @param type the {@linkplain EmbeddedDatabaseType embedded database type}
* @param customizer the customizer to return based on the default

View File

@ -45,11 +45,11 @@ import org.springframework.util.Assert;
* for the database.
* <li>Call {@link #setDatabaseName} to set an explicit name for the database.
* <li>Call {@link #setDatabaseType} to set the database type if you wish to
* use one of the supported types with their default settings.
* use one of the pre-supported types with its default settings.
* <li>Call {@link #setDatabaseConfigurer} to configure support for a custom
* embedded database type, or
* {@linkplain EmbeddedDatabaseConfigurers#customizeConfigurer customize} the
* default of a supported types.
* defaults for one of the pre-supported types.
* <li>Call {@link #setDatabasePopulator} to change the algorithm used to
* populate the database.
* <li>Call {@link #setDataSourceFactory} to change the type of
@ -128,7 +128,7 @@ public class EmbeddedDatabaseFactory {
/**
* Set the type of embedded database to use.
* <p>Call this when you wish to configure one of the pre-supported types
* with their default settings.
* with its default settings.
* <p>Defaults to HSQL.
* @param type the database type
*/

View File

@ -293,7 +293,8 @@ class NamedParameterUtilsTests {
"SELECT /*:doo*/':foo', :xxx FROM DUAL",
"SELECT ':foo'/*:doo*/, :xxx FROM DUAL",
"SELECT \":foo\"\":doo\", :xxx FROM DUAL",
"SELECT `:foo``:doo`, :xxx FROM DUAL",})
"SELECT `:foo``:doo`, :xxx FROM DUAL"
})
void parseSqlStatementWithParametersInsideQuote(String sql) {
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
assertThat(parsedSql.getTotalParameterCount()).isEqualTo(1);

View File

@ -36,33 +36,32 @@ import static org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType.
*/
class EmbeddedDatabaseBuilderTests {
private final EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(
getClass()));
private final EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
@Test
void addDefaultScripts() {
doTwice(() -> {
EmbeddedDatabase db = new EmbeddedDatabaseBuilder()//
.addDefaultScripts()//
.build();
EmbeddedDatabase db = new EmbeddedDatabaseBuilder()
.addDefaultScripts()
.build();
assertDatabaseCreatedAndShutdown(db);
});
}
@Test
void addScriptWithBogusFileName() {
assertThatExceptionOfType(CannotReadScriptException.class).isThrownBy(
new EmbeddedDatabaseBuilder().addScript("bogus.sql")::build);
assertThatExceptionOfType(CannotReadScriptException.class)
.isThrownBy(new EmbeddedDatabaseBuilder().addScript("bogus.sql")::build);
}
@Test
void addScript() {
doTwice(() -> {
EmbeddedDatabase db = builder//
.addScript("db-schema.sql")//
.addScript("db-test-data.sql")//
.build();
EmbeddedDatabase db = builder
.addScript("db-schema.sql")
.addScript("db-test-data.sql")
.build();
assertDatabaseCreatedAndShutdown(db);
});
}
@ -70,9 +69,9 @@ class EmbeddedDatabaseBuilderTests {
@Test
void addScripts() {
doTwice(() -> {
EmbeddedDatabase db = builder//
.addScripts("db-schema.sql", "db-test-data.sql")//
.build();
EmbeddedDatabase db = builder
.addScripts("db-schema.sql", "db-test-data.sql")
.build();
assertDatabaseCreatedAndShutdown(db);
});
}
@ -80,9 +79,9 @@ class EmbeddedDatabaseBuilderTests {
@Test
void addScriptsWithDefaultCommentPrefix() {
doTwice(() -> {
EmbeddedDatabase db = builder//
.addScripts("db-schema-comments.sql", "db-test-data.sql")//
.build();
EmbeddedDatabase db = builder
.addScripts("db-schema-comments.sql", "db-test-data.sql")
.build();
assertDatabaseCreatedAndShutdown(db);
});
}
@ -90,10 +89,10 @@ class EmbeddedDatabaseBuilderTests {
@Test
void addScriptsWithCustomCommentPrefix() {
doTwice(() -> {
EmbeddedDatabase db = builder//
.addScripts("db-schema-custom-comments.sql", "db-test-data.sql")//
.setCommentPrefix("~")//
.build();
EmbeddedDatabase db = builder
.addScripts("db-schema-custom-comments.sql", "db-test-data.sql")
.setCommentPrefix("~")
.build();
assertDatabaseCreatedAndShutdown(db);
});
}
@ -101,11 +100,11 @@ class EmbeddedDatabaseBuilderTests {
@Test
void addScriptsWithCustomBlockComments() {
doTwice(() -> {
EmbeddedDatabase db = builder//
.addScripts("db-schema-block-comments.sql", "db-test-data.sql")//
.setBlockCommentStartDelimiter("{*")//
.setBlockCommentEndDelimiter("*}")//
.build();
EmbeddedDatabase db = builder
.addScripts("db-schema-block-comments.sql", "db-test-data.sql")
.setBlockCommentStartDelimiter("{*")
.setBlockCommentEndDelimiter("*}")
.build();
assertDatabaseCreatedAndShutdown(db);
});
}
@ -113,10 +112,10 @@ class EmbeddedDatabaseBuilderTests {
@Test
void setTypeToH2() {
doTwice(() -> {
EmbeddedDatabase db = builder//
.setType(H2)//
.addScripts("db-schema.sql", "db-test-data.sql")//
.build();
EmbeddedDatabase db = builder
.setType(H2)
.addScripts("db-schema.sql", "db-test-data.sql")
.build();
assertDatabaseCreatedAndShutdown(db);
});
}
@ -132,7 +131,7 @@ class EmbeddedDatabaseBuilderTests {
super.configureConnectionProperties(properties, databaseName);
}
}))
.addScripts("db-schema.sql", "db-test-data.sql")//
.addScripts("db-schema.sql", "db-test-data.sql")
.build();
assertDatabaseCreatedAndShutdown(db);
});
@ -141,18 +140,17 @@ class EmbeddedDatabaseBuilderTests {
@Test
void setTypeToDerbyAndIgnoreFailedDrops() {
doTwice(() -> {
EmbeddedDatabase db = builder//
.setType(DERBY)//
.ignoreFailedDrops(true)//
.addScripts("db-schema-derby-with-drop.sql", "db-test-data.sql").build();
EmbeddedDatabase db = builder
.setType(DERBY)
.ignoreFailedDrops(true)
.addScripts("db-schema-derby-with-drop.sql", "db-test-data.sql").build();
assertDatabaseCreatedAndShutdown(db);
});
}
@Test
void createSameSchemaTwiceWithoutUniqueDbNames() {
EmbeddedDatabase db1 = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()))
.addScripts("db-schema-without-dropping.sql").build();
EmbeddedDatabase db1 = builder.addScripts("db-schema-without-dropping.sql").build();
try {
assertThatExceptionOfType(ScriptStatementFailedException.class).isThrownBy(() ->
new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())).addScripts("db-schema-without-dropping.sql").build());
@ -164,20 +162,20 @@ class EmbeddedDatabaseBuilderTests {
@Test
void createSameSchemaTwiceWithGeneratedUniqueDbNames() {
EmbeddedDatabase db1 = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()))//
.addScripts("db-schema-without-dropping.sql", "db-test-data.sql")//
.generateUniqueName(true)//
.build();
EmbeddedDatabase db1 = builder
.addScripts("db-schema-without-dropping.sql", "db-test-data.sql")
.generateUniqueName(true)
.build();
JdbcTemplate template1 = new JdbcTemplate(db1);
assertNumRowsInTestTable(template1, 1);
template1.update("insert into T_TEST (NAME) values ('Sam')");
assertNumRowsInTestTable(template1, 2);
EmbeddedDatabase db2 = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()))//
.addScripts("db-schema-without-dropping.sql", "db-test-data.sql")//
.generateUniqueName(true)//
.build();
EmbeddedDatabase db2 = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()))
.addScripts("db-schema-without-dropping.sql", "db-test-data.sql")
.generateUniqueName(true)
.build();
assertDatabaseCreated(db2);
db1.shutdown();

View File

@ -58,6 +58,16 @@ public class JsonPathExpectationsHelper {
private final Configuration configuration;
/**
* Construct a new {@code JsonPathExpectationsHelper} using the
* {@linkplain Configuration#defaultConfiguration() default configuration}.
* @param expression the {@link JsonPath} expression; never {@code null} or empty
* @since 6.2
*/
public JsonPathExpectationsHelper(String expression) {
this(expression, (Configuration) null);
}
/**
* Construct a new {@code JsonPathExpectationsHelper}.
* @param expression the {@link JsonPath} expression; never {@code null} or empty
@ -72,16 +82,6 @@ public class JsonPathExpectationsHelper {
this.configuration = (configuration != null) ? configuration : Configuration.defaultConfiguration();
}
/**
* Construct a new {@code JsonPathExpectationsHelper} using the
* {@linkplain Configuration#defaultConfiguration() default configuration}.
* @param expression the {@link JsonPath} expression; never {@code null} or empty
* @since 6.2
*/
public JsonPathExpectationsHelper(String expression) {
this(expression, (Configuration) null);
}
/**
* Construct a new {@code JsonPathExpectationsHelper}.
* @param expression the {@link JsonPath} expression; never {@code null} or empty

View File

@ -32,11 +32,11 @@ import org.springframework.lang.Nullable;
/**
* {@link Encoder} and {@link Decoder} that is able to handle a map to and from
* json. Used to configure the jsonpath infrastructure without having a hard
* JSON. Used to configure the jsonpath infrastructure without having a hard
* dependency on the library.
*
* @param encoder the json encoder
* @param decoder the json decoder
* @param encoder the JSON encoder
* @param decoder the JSON decoder
* @author Stephane Nicoll
* @author Rossen Stoyanchev
* @since 6.2
@ -69,9 +69,9 @@ record JsonEncoderDecoder(Encoder<?> encoder, Decoder<?> decoder) {
/**
* Find the first suitable {@link Encoder} that can encode a {@link Map}
* to json.
* to JSON.
* @param writers the writers to inspect
* @return a suitable json {@link Encoder} or {@code null}
* @return a suitable JSON {@link Encoder} or {@code null}
*/
@Nullable
private static Encoder<?> findJsonEncoder(Collection<HttpMessageWriter<?>> writers) {
@ -90,9 +90,9 @@ record JsonEncoderDecoder(Encoder<?> encoder, Decoder<?> decoder) {
/**
* Find the first suitable {@link Decoder} that can decode a {@link Map} to
* json.
* JSON.
* @param readers the readers to inspect
* @return a suitable json {@link Decoder} or {@code null}
* @return a suitable JSON {@link Decoder} or {@code null}
*/
@Nullable
private static Decoder<?> findJsonDecoder(Collection<HttpMessageReader<?>> readers) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.