Add missing author tags and sync SQL script support for JDBC & R2DBC

This commit is contained in:
Sam Brannen 2021-05-16 17:18:56 +02:00
parent 8da049b613
commit c80c4e001a
23 changed files with 176 additions and 171 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +29,7 @@ import org.springframework.core.io.support.EncodedResource;
public class CannotReadScriptException extends ScriptException { public class CannotReadScriptException extends ScriptException {
/** /**
* Construct a new {@code CannotReadScriptException}. * Create a new {@code CannotReadScriptException}.
* @param resource the resource that cannot be read from * @param resource the resource that cannot be read from
* @param cause the underlying cause of the resource access failure * @param cause the underlying cause of the resource access failure
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,6 +23,8 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.springframework.util.Assert;
/** /**
* Composite {@link DatabasePopulator} that delegates to a list of given * Composite {@link DatabasePopulator} that delegates to a list of given
* {@code DatabasePopulator} implementations, executing all scripts. * {@code DatabasePopulator} implementations, executing all scripts.
@ -52,6 +54,7 @@ public class CompositeDatabasePopulator implements DatabasePopulator {
* @since 4.3 * @since 4.3
*/ */
public CompositeDatabasePopulator(Collection<DatabasePopulator> populators) { public CompositeDatabasePopulator(Collection<DatabasePopulator> populators) {
Assert.notNull(populators, "DatabasePopulators must not be null");
this.populators.addAll(populators); this.populators.addAll(populators);
} }
@ -61,6 +64,7 @@ public class CompositeDatabasePopulator implements DatabasePopulator {
* @since 4.3 * @since 4.3
*/ */
public CompositeDatabasePopulator(DatabasePopulator... populators) { public CompositeDatabasePopulator(DatabasePopulator... populators) {
Assert.notNull(populators, "DatabasePopulators must not be null");
this.populators.addAll(Arrays.asList(populators)); this.populators.addAll(Arrays.asList(populators));
} }
@ -69,6 +73,7 @@ public class CompositeDatabasePopulator implements DatabasePopulator {
* Specify one or more populators to delegate to. * Specify one or more populators to delegate to.
*/ */
public void setPopulators(DatabasePopulator... populators) { public void setPopulators(DatabasePopulator... populators) {
Assert.notNull(populators, "DatabasePopulators must not be null");
this.populators.clear(); this.populators.clear();
this.populators.addAll(Arrays.asList(populators)); this.populators.addAll(Arrays.asList(populators));
} }
@ -77,12 +82,13 @@ public class CompositeDatabasePopulator implements DatabasePopulator {
* Add one or more populators to the list of delegates. * Add one or more populators to the list of delegates.
*/ */
public void addPopulators(DatabasePopulator... populators) { public void addPopulators(DatabasePopulator... populators) {
Assert.notNull(populators, "DatabasePopulators must not be null");
this.populators.addAll(Arrays.asList(populators)); this.populators.addAll(Arrays.asList(populators));
} }
@Override @Override
public void populate(Connection connection) throws SQLException, ScriptException { public void populate(Connection connection) throws SQLException, ScriptException {
Assert.notNull(connection, "Connection must not be null");
for (DatabasePopulator populator : this.populators) { for (DatabasePopulator populator : this.populators) {
populator.populate(connection); populator.populate(connection);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,7 +30,7 @@ import org.springframework.lang.Nullable;
public abstract class ScriptException extends DataAccessException { public abstract class ScriptException extends DataAccessException {
/** /**
* Constructor for {@code ScriptException}. * Create a new {@code ScriptException}.
* @param message the detail message * @param message the detail message
*/ */
public ScriptException(String message) { public ScriptException(String message) {
@ -38,7 +38,7 @@ public abstract class ScriptException extends DataAccessException {
} }
/** /**
* Constructor for {@code ScriptException}. * Create a new {@code ScriptException}.
* @param message the detail message * @param message the detail message
* @param cause the root cause * @param cause the root cause
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +29,7 @@ import org.springframework.lang.Nullable;
public class ScriptParseException extends ScriptException { public class ScriptParseException extends ScriptException {
/** /**
* Construct a new {@code ScriptParseException}. * Create a new {@code ScriptParseException}.
* @param message detailed message * @param message detailed message
* @param resource the resource from which the SQL script was read * @param resource the resource from which the SQL script was read
*/ */
@ -38,7 +38,7 @@ public class ScriptParseException extends ScriptException {
} }
/** /**
* Construct a new {@code ScriptParseException}. * Create a new {@code ScriptParseException}.
* @param message detailed message * @param message detailed message
* @param resource the resource from which the SQL script was read * @param resource the resource from which the SQL script was read
* @param cause the underlying cause of the failure * @param cause the underlying cause of the failure

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,7 +28,7 @@ package org.springframework.jdbc.datasource.init;
public class UncategorizedScriptException extends ScriptException { public class UncategorizedScriptException extends ScriptException {
/** /**
* Construct a new {@code UncategorizedScriptException}. * Create a new {@code UncategorizedScriptException}.
* @param message detailed message * @param message detailed message
*/ */
public UncategorizedScriptException(String message) { public UncategorizedScriptException(String message) {
@ -36,7 +36,7 @@ public class UncategorizedScriptException extends ScriptException {
} }
/** /**
* Construct a new {@code UncategorizedScriptException}. * Create a new {@code UncategorizedScriptException}.
* @param message detailed message * @param message detailed message
* @param cause the root cause * @param cause the root cause
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,15 +29,13 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Abstract base class for integration tests involving database initialization. * Abstract base class for integration tests involving database initialization.
* *
* @author Sam Brannen * @author Sam Brannen
* @since 4.0.3 * @since 4.0.3
*/ */
public abstract class AbstractDatabaseInitializationTests { abstract class AbstractDatabaseInitializationTests {
private final ClassRelativeResourceLoader resourceLoader = new ClassRelativeResourceLoader(getClass()); private final ClassRelativeResourceLoader resourceLoader = new ClassRelativeResourceLoader(getClass());
@ -47,13 +45,13 @@ public abstract class AbstractDatabaseInitializationTests {
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
db = new EmbeddedDatabaseBuilder().setType(getEmbeddedDatabaseType()).build(); db = new EmbeddedDatabaseBuilder().setType(getEmbeddedDatabaseType()).build();
jdbcTemplate = new JdbcTemplate(db); jdbcTemplate = new JdbcTemplate(db);
} }
@AfterEach @AfterEach
public void shutDown() { void shutDown() {
if (TransactionSynchronizationManager.isSynchronizationActive()) { if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.clear(); TransactionSynchronizationManager.clear();
TransactionSynchronizationManager.unbindResource(db); TransactionSynchronizationManager.unbindResource(db);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,7 +34,7 @@ import static org.mockito.Mockito.verify;
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 4.3 * @since 4.3
*/ */
public class CompositeDatabasePopulatorTests { class CompositeDatabasePopulatorTests {
private final Connection mockedConnection = mock(Connection.class); private final Connection mockedConnection = mock(Connection.class);
@ -44,49 +44,59 @@ public class CompositeDatabasePopulatorTests {
@Test @Test
public void addPopulators() throws SQLException { void addPopulators() throws SQLException {
CompositeDatabasePopulator populator = new CompositeDatabasePopulator(); CompositeDatabasePopulator populator = new CompositeDatabasePopulator();
populator.addPopulators(mockedDatabasePopulator1, mockedDatabasePopulator2); populator.addPopulators(mockedDatabasePopulator1, mockedDatabasePopulator2);
populator.populate(mockedConnection);
verify(mockedDatabasePopulator1,times(1)).populate(mockedConnection);
verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection);
}
@Test
public void setPopulatorsWithMultiple() throws SQLException {
CompositeDatabasePopulator populator = new CompositeDatabasePopulator();
populator.setPopulators(mockedDatabasePopulator1, mockedDatabasePopulator2); // multiple
populator.populate(mockedConnection); populator.populate(mockedConnection);
verify(mockedDatabasePopulator1, times(1)).populate(mockedConnection); verify(mockedDatabasePopulator1, times(1)).populate(mockedConnection);
verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection); verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection);
} }
@Test @Test
public void setPopulatorsForOverride() throws SQLException { void setPopulatorsWithMultiple() throws SQLException {
CompositeDatabasePopulator populator = new CompositeDatabasePopulator();
populator.setPopulators(mockedDatabasePopulator1, mockedDatabasePopulator2); // multiple
populator.populate(mockedConnection);
verify(mockedDatabasePopulator1, times(1)).populate(mockedConnection);
verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection);
}
@Test
void setPopulatorsForOverride() throws SQLException {
CompositeDatabasePopulator populator = new CompositeDatabasePopulator(); CompositeDatabasePopulator populator = new CompositeDatabasePopulator();
populator.setPopulators(mockedDatabasePopulator1); populator.setPopulators(mockedDatabasePopulator1);
populator.setPopulators(mockedDatabasePopulator2); // override populator.setPopulators(mockedDatabasePopulator2); // override
populator.populate(mockedConnection); populator.populate(mockedConnection);
verify(mockedDatabasePopulator1, times(0)).populate(mockedConnection); verify(mockedDatabasePopulator1, times(0)).populate(mockedConnection);
verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection); verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection);
} }
@Test @Test
public void constructWithVarargs() throws SQLException { void constructWithVarargs() throws SQLException {
CompositeDatabasePopulator populator = CompositeDatabasePopulator populator =
new CompositeDatabasePopulator(mockedDatabasePopulator1, mockedDatabasePopulator2); new CompositeDatabasePopulator(mockedDatabasePopulator1, mockedDatabasePopulator2);
populator.populate(mockedConnection); populator.populate(mockedConnection);
verify(mockedDatabasePopulator1, times(1)).populate(mockedConnection); verify(mockedDatabasePopulator1, times(1)).populate(mockedConnection);
verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection); verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection);
} }
@Test @Test
public void constructWithCollection() throws SQLException { void constructWithCollection() throws SQLException {
Set<DatabasePopulator> populators = new LinkedHashSet<>(); Set<DatabasePopulator> populators = new LinkedHashSet<>();
populators.add(mockedDatabasePopulator1); populators.add(mockedDatabasePopulator1);
populators.add(mockedDatabasePopulator2); populators.add(mockedDatabasePopulator2);
CompositeDatabasePopulator populator = new CompositeDatabasePopulator(populators); CompositeDatabasePopulator populator = new CompositeDatabasePopulator(populators);
populator.populate(mockedConnection); populator.populate(mockedConnection);
verify(mockedDatabasePopulator1, times(1)).populate(mockedConnection); verify(mockedDatabasePopulator1, times(1)).populate(mockedConnection);
verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection); verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection);
} }

View File

@ -26,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Sam Brannen * @author Sam Brannen
* @since 4.0.3 * @since 4.0.3
*/ */
class H2DatabasePopulatorTests extends AbstractDatabasePopulatorTests { class H2DatabasePopulatorIntegrationTests extends AbstractDatabasePopulatorTests {
@Override @Override
protected EmbeddedDatabaseType getEmbeddedDatabaseType() { protected EmbeddedDatabaseType getEmbeddedDatabaseType() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,12 +17,12 @@
package org.springframework.jdbc.datasource.init; package org.springframework.jdbc.datasource.init;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.BDDMockito.mock;
/** /**
* Unit tests for {@link ResourceDatabasePopulator}. * Unit tests for {@link ResourceDatabasePopulator}.
@ -31,84 +31,84 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* @since 4.1 * @since 4.1
* @see AbstractDatabasePopulatorTests * @see AbstractDatabasePopulatorTests
*/ */
public class ResourceDatabasePopulatorTests { class ResourceDatabasePopulatorUnitTests {
private static final Resource script1 = Mockito.mock(Resource.class); private static final Resource script1 = mock(Resource.class);
private static final Resource script2 = Mockito.mock(Resource.class); private static final Resource script2 = mock(Resource.class);
private static final Resource script3 = Mockito.mock(Resource.class); private static final Resource script3 = mock(Resource.class);
@Test @Test
public void constructWithNullResource() { void constructWithNullResource() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
new ResourceDatabasePopulator((Resource) null)); new ResourceDatabasePopulator((Resource) null));
} }
@Test @Test
public void constructWithNullResourceArray() { void constructWithNullResourceArray() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
new ResourceDatabasePopulator((Resource[]) null)); new ResourceDatabasePopulator((Resource[]) null));
} }
@Test @Test
public void constructWithResource() { void constructWithResource() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1);
assertThat(databasePopulator.scripts.size()).isEqualTo(1); assertThat(databasePopulator.scripts).hasSize(1);
} }
@Test @Test
public void constructWithMultipleResources() { void constructWithMultipleResources() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1, script2); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1, script2);
assertThat(databasePopulator.scripts.size()).isEqualTo(2); assertThat(databasePopulator.scripts).hasSize(2);
} }
@Test @Test
public void constructWithMultipleResourcesAndThenAddScript() { void constructWithMultipleResourcesAndThenAddScript() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1, script2); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1, script2);
assertThat(databasePopulator.scripts.size()).isEqualTo(2); assertThat(databasePopulator.scripts).hasSize(2);
databasePopulator.addScript(script3); databasePopulator.addScript(script3);
assertThat(databasePopulator.scripts.size()).isEqualTo(3); assertThat(databasePopulator.scripts).hasSize(3);
} }
@Test @Test
public void addScriptsWithNullResource() { void addScriptsWithNullResource() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
databasePopulator.addScripts((Resource) null)); databasePopulator.addScripts((Resource) null));
} }
@Test @Test
public void addScriptsWithNullResourceArray() { void addScriptsWithNullResourceArray() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
databasePopulator.addScripts((Resource[]) null)); databasePopulator.addScripts((Resource[]) null));
} }
@Test @Test
public void setScriptsWithNullResource() { void setScriptsWithNullResource() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
databasePopulator.setScripts((Resource) null)); databasePopulator.setScripts((Resource) null));
} }
@Test @Test
public void setScriptsWithNullResourceArray() { void setScriptsWithNullResourceArray() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
databasePopulator.setScripts((Resource[]) null)); databasePopulator.setScripts((Resource[]) null));
} }
@Test @Test
public void setScriptsAndThenAddScript() { void setScriptsAndThenAddScript() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
assertThat(databasePopulator.scripts.size()).isEqualTo(0); assertThat(databasePopulator.scripts).isEmpty();
databasePopulator.setScripts(script1, script2); databasePopulator.setScripts(script1, script2);
assertThat(databasePopulator.scripts.size()).isEqualTo(2); assertThat(databasePopulator.scripts).hasSize(2);
databasePopulator.addScript(script3); databasePopulator.addScript(script3);
assertThat(databasePopulator.scripts.size()).isEqualTo(3); assertThat(databasePopulator.scripts).hasSize(3);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,8 @@ import org.springframework.core.io.support.EncodedResource;
/** /**
* Thrown by {@link ScriptUtils} if an SQL script cannot be read. * Thrown by {@link ScriptUtils} if an SQL script cannot be read.
* *
* @author Keith Donald
* @author Sam Brannen
* @author Mark Paluch * @author Mark Paluch
* @since 5.3 * @since 5.3
*/ */
@ -29,8 +31,8 @@ public class CannotReadScriptException extends ScriptException {
/** /**
* Create a new {@code CannotReadScriptException}. * Create a new {@code CannotReadScriptException}.
* @param resource the resource that cannot be read from. * @param resource the resource that cannot be read from
* @param cause the underlying cause of the resource access failure. * @param cause the underlying cause of the resource access failure
*/ */
public CannotReadScriptException(EncodedResource resource, Throwable cause) { public CannotReadScriptException(EncodedResource resource, Throwable cause) {
super("Cannot read SQL script from " + resource, cause); super("Cannot read SQL script from " + resource, cause);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,8 +29,12 @@ import org.springframework.util.Assert;
/** /**
* Composite {@link DatabasePopulator} that delegates to a list of given * Composite {@link DatabasePopulator} that delegates to a list of given
* {@link DatabasePopulator} implementations, executing all scripts. * {@code DatabasePopulator} implementations, executing all scripts.
* *
* @author Dave Syer
* @author Juergen Hoeller
* @author Sam Brannen
* @author Kazuki Shimizu
* @author Mark Paluch * @author Mark Paluch
* @since 5.3 * @since 5.3
*/ */
@ -44,14 +48,15 @@ public class CompositeDatabasePopulator implements DatabasePopulator {
* @see #setPopulators * @see #setPopulators
* @see #addPopulators * @see #addPopulators
*/ */
public CompositeDatabasePopulator() {} public CompositeDatabasePopulator() {
}
/** /**
* Create a {@code CompositeDatabasePopulator}. with the given populators. * Create a {@code CompositeDatabasePopulator}. with the given populators.
* @param populators one or more populators to delegate to. * @param populators one or more populators to delegate to.
*/ */
public CompositeDatabasePopulator(Collection<DatabasePopulator> populators) { public CompositeDatabasePopulator(Collection<DatabasePopulator> populators) {
Assert.notNull(populators, "Collection of DatabasePopulator must not be null"); Assert.notNull(populators, "DatabasePopulators must not be null");
this.populators.addAll(populators); this.populators.addAll(populators);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,6 +28,8 @@ import org.springframework.util.Assert;
* initialization and {@link #setDatabaseCleaner clean up} a database during * initialization and {@link #setDatabaseCleaner clean up} a database during
* destruction. * destruction.
* *
* @author Dave Syer
* @author Sam Brannen
* @author Mark Paluch * @author Mark Paluch
* @since 5.3 * @since 5.3
* @see DatabasePopulator * @see DatabasePopulator
@ -50,7 +52,7 @@ public class ConnectionFactoryInitializer implements InitializingBean, Disposabl
* The {@link ConnectionFactory} for the database to populate when this * The {@link ConnectionFactory} for the database to populate when this
* component is initialized and to clean up when this component is shut down. * component is initialized and to clean up when this component is shut down.
* <p>This property is mandatory with no default provided. * <p>This property is mandatory with no default provided.
* @param connectionFactory the R2DBC {@link ConnectionFactory}. * @param connectionFactory the R2DBC {@link ConnectionFactory}
*/ */
public void setConnectionFactory(ConnectionFactory connectionFactory) { public void setConnectionFactory(ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory; this.connectionFactory = connectionFactory;
@ -66,10 +68,9 @@ public class ConnectionFactoryInitializer implements InitializingBean, Disposabl
} }
/** /**
* Set the {@link DatabasePopulator} to execute during the bean destruction phase, cleaning up the database and * Set the {@link DatabasePopulator} to execute during the bean destruction
* leaving it in a known state for others. * phase, cleaning up the database and leaving it in a known state for others.
* * @param databaseCleaner the {@code DatabasePopulator} to use during destruction
* @param databaseCleaner the {@link DatabasePopulator} to use during destruction
* @see #setDatabasePopulator * @see #setDatabasePopulator
*/ */
public void setDatabaseCleaner(DatabasePopulator databaseCleaner) { public void setDatabaseCleaner(DatabasePopulator databaseCleaner) {
@ -77,8 +78,8 @@ public class ConnectionFactoryInitializer implements InitializingBean, Disposabl
} }
/** /**
* Flag to explicitly enable or disable the {@link #setDatabasePopulator database populator} * Flag to explicitly enable or disable the {@linkplain #setDatabasePopulator
* and {@link #setDatabaseCleaner database cleaner}. * database populator} and {@linkplain #setDatabaseCleaner database cleaner}.
* @param enabled {@code true} if the database populator and database cleaner * @param enabled {@code true} if the database populator and database cleaner
* should be called on startup and shutdown, respectively * should be called on startup and shutdown, respectively
*/ */
@ -88,7 +89,8 @@ public class ConnectionFactoryInitializer implements InitializingBean, Disposabl
/** /**
* Use the {@link #setDatabasePopulator database populator} to set up the database. * Use the {@linkplain #setDatabasePopulator database populator} to set up
* the database.
*/ */
@Override @Override
public void afterPropertiesSet() { public void afterPropertiesSet() {
@ -96,7 +98,8 @@ public class ConnectionFactoryInitializer implements InitializingBean, Disposabl
} }
/** /**
* Use the {@link #setDatabaseCleaner database cleaner} to clean up the database. * Use the {@linkplain #setDatabaseCleaner database cleaner} to clean up the
* database.
*/ */
@Override @Override
public void destroy() { public void destroy() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,6 +28,8 @@ import org.springframework.util.Assert;
* Strategy used to populate, initialize, or clean up a database. * Strategy used to populate, initialize, or clean up a database.
* *
* @author Mark Paluch * @author Mark Paluch
* @author Keith Donald
* @author Sam Brannen
* @since 5.3 * @since 5.3
* @see ResourceDatabasePopulator * @see ResourceDatabasePopulator
* @see ConnectionFactoryInitializer * @see ConnectionFactoryInitializer

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,8 +20,10 @@ import org.springframework.dao.DataAccessException;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
/** /**
* Root of the hierarchy of data access exceptions that are related to processing of SQL scripts. * Root of the hierarchy of data access exceptions that are related to processing
* of SQL scripts.
* *
* @author Sam Brannen
* @author Mark Paluch * @author Mark Paluch
* @since 5.3 * @since 5.3
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,6 +22,7 @@ import org.springframework.lang.Nullable;
/** /**
* Thrown by {@link ScriptUtils} if an SQL script cannot be properly parsed. * Thrown by {@link ScriptUtils} if an SQL script cannot be properly parsed.
* *
* @author Sam Brannen
* @author Mark Paluch * @author Mark Paluch
* @since 5.3 * @since 5.3
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,6 +22,8 @@ import org.springframework.core.io.support.EncodedResource;
* Thrown by {@link ScriptUtils} if a statement in an SQL script failed when * Thrown by {@link ScriptUtils} if a statement in an SQL script failed when
* executing it against the target database. * executing it against the target database.
* *
* @author Juergen Hoeller
* @author Sam Brannen
* @author Mark Paluch * @author Mark Paluch
* @since 5.3 * @since 5.3
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,10 +17,11 @@
package org.springframework.r2dbc.connection.init; package org.springframework.r2dbc.connection.init;
/** /**
* Thrown when we cannot determine anything more specific than "something went wrong while * Thrown when we cannot determine anything more specific than "something went wrong
* processing an SQL script": for example, a {@link io.r2dbc.spi.R2dbcException} from * while processing an SQL script": for example, an {@link io.r2dbc.spi.R2dbcException}
* R2DBC that we cannot pinpoint more precisely. * from R2DBC that we cannot pinpoint more precisely.
* *
* @author Sam Brannen
* @author Mark Paluch * @author Mark Paluch
* @since 5.3 * @since 5.3
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,22 +24,23 @@ import org.springframework.core.io.ClassRelativeResourceLoader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.r2dbc.core.DatabaseClient; import org.springframework.r2dbc.core.DatabaseClient;
/** /**
* Abstract test support for {@link DatabasePopulator}. * Abstract test support for {@link DatabasePopulator}.
* *
* @author Dave Syer
* @author Sam Brannen
* @author Oliver Gierke
* @author Mark Paluch * @author Mark Paluch
*/ */
public abstract class AbstractDatabaseInitializationTests { abstract class AbstractDatabasePopulatorTests {
ClassRelativeResourceLoader resourceLoader = new ClassRelativeResourceLoader( ClassRelativeResourceLoader resourceLoader = new ClassRelativeResourceLoader(getClass());
getClass());
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
@Test @Test
public void scriptWithSingleLineCommentsAndFailedDrop() { void scriptWithSingleLineCommentsAndFailedDrop() {
databasePopulator.addScript(resource("db-schema-failed-drop-comments.sql")); databasePopulator.addScript(resource("db-schema-failed-drop-comments.sql"));
databasePopulator.addScript(resource("db-test-data.sql")); databasePopulator.addScript(resource("db-test-data.sql"));
databasePopulator.setIgnoreFailedDrops(true); databasePopulator.setIgnoreFailedDrops(true);
@ -56,7 +57,7 @@ public abstract class AbstractDatabaseInitializationTests {
} }
@Test @Test
public void scriptWithStandardEscapedLiteral() { void scriptWithStandardEscapedLiteral() {
databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(defaultSchema());
databasePopulator.addScript(resource("db-test-data-escaped-literal.sql")); databasePopulator.addScript(resource("db-test-data-escaped-literal.sql"));
@ -66,7 +67,7 @@ public abstract class AbstractDatabaseInitializationTests {
} }
@Test @Test
public void scriptWithMySqlEscapedLiteral() { void scriptWithMySqlEscapedLiteral() {
databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(defaultSchema());
databasePopulator.addScript(resource("db-test-data-mysql-escaped-literal.sql")); databasePopulator.addScript(resource("db-test-data-mysql-escaped-literal.sql"));
@ -76,7 +77,7 @@ public abstract class AbstractDatabaseInitializationTests {
} }
@Test @Test
public void scriptWithMultipleStatements() { void scriptWithMultipleStatements() {
databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(defaultSchema());
databasePopulator.addScript(resource("db-test-data-multiple.sql")); databasePopulator.addScript(resource("db-test-data-multiple.sql"));
@ -86,7 +87,7 @@ public abstract class AbstractDatabaseInitializationTests {
} }
@Test @Test
public void scriptWithMultipleStatementsAndLongSeparator() { void scriptWithMultipleStatementsAndLongSeparator() {
databasePopulator.addScript(defaultSchema()); databasePopulator.addScript(defaultSchema());
databasePopulator.addScript(resource("db-test-data-endings.sql")); databasePopulator.addScript(resource("db-test-data-endings.sql"));
databasePopulator.setSeparator("@@"); databasePopulator.setSeparator("@@");
@ -120,15 +121,13 @@ public abstract class AbstractDatabaseInitializationTests {
DatabaseClient client = DatabaseClient.create(connectionFactory); DatabaseClient client = DatabaseClient.create(connectionFactory);
for (String lastName : lastNames) { for (String lastName : lastNames) {
client.sql("select count(0) from users where last_name = :name") // client.sql("select count(0) from users where last_name = :name") //
.bind("name", lastName) // .bind("name", lastName) //
.map((row, metadata) -> row.get(0)) // .map((row, metadata) -> row.get(0)) //
.first() // .first() //
.map(number -> ((Number) number).intValue()) // .map(number -> ((Number) number).intValue()) //
.as(StepVerifier::create) // .as(StepVerifier::create) //
.expectNext(1).as( .expectNext(1).as("Did not find user with last name [" + lastName + "].") //
"Did not find user with last name [" + lastName + "].") //
.verifyComplete(); .verifyComplete();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,9 +33,11 @@ import static org.mockito.BDDMockito.when;
/** /**
* Unit tests for {@link CompositeDatabasePopulator}. * Unit tests for {@link CompositeDatabasePopulator}.
* *
* @author Kazuki Shimizu
* @author Juergen Hoeller
* @author Mark Paluch * @author Mark Paluch
*/ */
public class CompositeDatabasePopulatorTests { class CompositeDatabasePopulatorTests {
Connection mockedConnection = mock(Connection.class); Connection mockedConnection = mock(Connection.class);
@ -45,15 +47,13 @@ public class CompositeDatabasePopulatorTests {
@BeforeEach @BeforeEach
public void before() { void before() {
when(mockedDatabasePopulator1.populate(mockedConnection)).thenReturn( when(mockedDatabasePopulator1.populate(mockedConnection)).thenReturn(Mono.empty());
Mono.empty()); when(mockedDatabasePopulator2.populate(mockedConnection)).thenReturn(Mono.empty());
when(mockedDatabasePopulator2.populate(mockedConnection)).thenReturn(
Mono.empty());
} }
@Test @Test
public void addPopulators() { void addPopulators() {
CompositeDatabasePopulator populator = new CompositeDatabasePopulator(); CompositeDatabasePopulator populator = new CompositeDatabasePopulator();
populator.addPopulators(mockedDatabasePopulator1, mockedDatabasePopulator2); populator.addPopulators(mockedDatabasePopulator1, mockedDatabasePopulator2);
@ -64,7 +64,7 @@ public class CompositeDatabasePopulatorTests {
} }
@Test @Test
public void setPopulatorsWithMultiple() { void setPopulatorsWithMultiple() {
CompositeDatabasePopulator populator = new CompositeDatabasePopulator(); CompositeDatabasePopulator populator = new CompositeDatabasePopulator();
populator.setPopulators(mockedDatabasePopulator1, mockedDatabasePopulator2); // multiple populator.setPopulators(mockedDatabasePopulator1, mockedDatabasePopulator2); // multiple
@ -75,7 +75,7 @@ public class CompositeDatabasePopulatorTests {
} }
@Test @Test
public void setPopulatorsForOverride() { void setPopulatorsForOverride() {
CompositeDatabasePopulator populator = new CompositeDatabasePopulator(); CompositeDatabasePopulator populator = new CompositeDatabasePopulator();
populator.setPopulators(mockedDatabasePopulator1); populator.setPopulators(mockedDatabasePopulator1);
populator.setPopulators(mockedDatabasePopulator2); // override populator.setPopulators(mockedDatabasePopulator2); // override
@ -87,9 +87,9 @@ public class CompositeDatabasePopulatorTests {
} }
@Test @Test
public void constructWithVarargs() { void constructWithVarargs() {
CompositeDatabasePopulator populator = new CompositeDatabasePopulator( CompositeDatabasePopulator populator =
mockedDatabasePopulator1, mockedDatabasePopulator2); new CompositeDatabasePopulator(mockedDatabasePopulator1, mockedDatabasePopulator2);
populator.populate(mockedConnection).as(StepVerifier::create).verifyComplete(); populator.populate(mockedConnection).as(StepVerifier::create).verifyComplete();
@ -98,7 +98,7 @@ public class CompositeDatabasePopulatorTests {
} }
@Test @Test
public void constructWithCollection() { void constructWithCollection() {
Set<DatabasePopulator> populators = new LinkedHashSet<>(); Set<DatabasePopulator> populators = new LinkedHashSet<>();
populators.add(mockedDatabasePopulator1); populators.add(mockedDatabasePopulator1);
populators.add(mockedDatabasePopulator2); populators.add(mockedDatabasePopulator2);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,7 +32,7 @@ import static org.mockito.BDDMockito.when;
* *
* @author Mark Paluch * @author Mark Paluch
*/ */
public class ConnectionFactoryInitializerUnitTests { class ConnectionFactoryInitializerUnitTests {
AtomicBoolean called = new AtomicBoolean(); AtomicBoolean called = new AtomicBoolean();
@ -40,12 +40,11 @@ public class ConnectionFactoryInitializerUnitTests {
MockConnection connection = MockConnection.builder().build(); MockConnection connection = MockConnection.builder().build();
MockConnectionFactory connectionFactory = MockConnectionFactory.builder().connection( MockConnectionFactory connectionFactory = MockConnectionFactory.builder().connection(connection).build();
connection).build();
@Test @Test
public void shouldInitializeConnectionFactory() { void shouldInitializeConnectionFactory() {
when(populator.populate(connectionFactory)).thenReturn( when(populator.populate(connectionFactory)).thenReturn(
Mono.<Void> empty().doOnSubscribe(subscription -> called.set(true))); Mono.<Void> empty().doOnSubscribe(subscription -> called.set(true)));
@ -59,7 +58,7 @@ public class ConnectionFactoryInitializerUnitTests {
} }
@Test @Test
public void shouldCleanConnectionFactory() { void shouldCleanConnectionFactory() {
when(populator.populate(connectionFactory)).thenReturn( when(populator.populate(connectionFactory)).thenReturn(
Mono.<Void> empty().doOnSubscribe(subscription -> called.set(true))); Mono.<Void> empty().doOnSubscribe(subscription -> called.set(true)));
@ -67,7 +66,6 @@ public class ConnectionFactoryInitializerUnitTests {
initializer.setConnectionFactory(connectionFactory); initializer.setConnectionFactory(connectionFactory);
initializer.setDatabaseCleaner(populator); initializer.setDatabaseCleaner(populator);
initializer.afterPropertiesSet();
initializer.destroy(); initializer.destroy();
assertThat(called).isTrue(); assertThat(called).isTrue();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,16 +20,13 @@ import java.util.UUID;
import io.r2dbc.spi.ConnectionFactories; import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.ConnectionFactory;
import org.junit.jupiter.api.Test;
import reactor.test.StepVerifier;
/** /**
* Integration tests for {@link DatabasePopulator} using H2. * Integration tests for {@link DatabasePopulator} using H2.
* *
* @author Mark Paluch * @author Mark Paluch
*/ */
public class H2DatabasePopulatorIntegrationTests class H2DatabasePopulatorIntegrationTests extends AbstractDatabasePopulatorTests {
extends AbstractDatabaseInitializationTests {
UUID databaseName = UUID.randomUUID(); UUID databaseName = UUID.randomUUID();
@ -42,20 +39,4 @@ public class H2DatabasePopulatorIntegrationTests
return this.connectionFactory; return this.connectionFactory;
} }
@Test
public void shouldRunScript() {
databasePopulator.addScript(usersSchema());
databasePopulator.addScript(resource("db-test-data-h2.sql"));
// Set statement separator to double newline so that ";" is not
// considered a statement separator within the source code of the
// aliased function 'REVERSE'.
databasePopulator.setSeparator("\n\n");
databasePopulator.populate(connectionFactory).as(
StepVerifier::create).verifyComplete();
assertUsersDatabaseCreated(connectionFactory, "White");
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,47 +27,43 @@ import static org.mockito.BDDMockito.mock;
/** /**
* Unit tests for {@link ResourceDatabasePopulator}. * Unit tests for {@link ResourceDatabasePopulator}.
* *
* @author Sam Brannen
* @author Mark Paluch * @author Mark Paluch
*/ */
public class ResourceDatabasePopulatorUnitTests { class ResourceDatabasePopulatorUnitTests {
private static final Resource script1 = mock(Resource.class); private static final Resource script1 = mock(Resource.class);
private static final Resource script2 = mock(Resource.class); private static final Resource script2 = mock(Resource.class);
private static final Resource script3 = mock(Resource.class); private static final Resource script3 = mock(Resource.class);
@Test @Test
public void constructWithNullResource() { void constructWithNullResource() {
assertThatIllegalArgumentException().isThrownBy( assertThatIllegalArgumentException().isThrownBy(() ->
() -> new ResourceDatabasePopulator((Resource) null)); new ResourceDatabasePopulator((Resource) null));
} }
@Test @Test
public void constructWithNullResourceArray() { void constructWithNullResourceArray() {
assertThatIllegalArgumentException().isThrownBy( assertThatIllegalArgumentException().isThrownBy(() ->
() -> new ResourceDatabasePopulator((Resource[]) null)); new ResourceDatabasePopulator((Resource[]) null));
} }
@Test @Test
public void constructWithResource() { void constructWithResource() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator( ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1);
script1);
assertThat(databasePopulator.scripts).hasSize(1); assertThat(databasePopulator.scripts).hasSize(1);
} }
@Test @Test
public void constructWithMultipleResources() { void constructWithMultipleResources() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator( ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1, script2);
script1, script2);
assertThat(databasePopulator.scripts).hasSize(2); assertThat(databasePopulator.scripts).hasSize(2);
} }
@Test @Test
public void constructWithMultipleResourcesAndThenAddScript() { void constructWithMultipleResourcesAndThenAddScript() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator( ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1, script2);
script1, script2);
assertThat(databasePopulator.scripts).hasSize(2); assertThat(databasePopulator.scripts).hasSize(2);
databasePopulator.addScript(script3); databasePopulator.addScript(script3);
@ -75,35 +71,35 @@ public class ResourceDatabasePopulatorUnitTests {
} }
@Test @Test
public void addScriptsWithNullResource() { void addScriptsWithNullResource() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
assertThatIllegalArgumentException().isThrownBy( assertThatIllegalArgumentException().isThrownBy(() ->
() -> databasePopulator.addScripts((Resource) null)); databasePopulator.addScripts((Resource) null));
} }
@Test @Test
public void addScriptsWithNullResourceArray() { void addScriptsWithNullResourceArray() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
assertThatIllegalArgumentException().isThrownBy( assertThatIllegalArgumentException().isThrownBy(() ->
() -> databasePopulator.addScripts((Resource[]) null)); databasePopulator.addScripts((Resource[]) null));
} }
@Test @Test
public void setScriptsWithNullResource() { void setScriptsWithNullResource() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
assertThatIllegalArgumentException().isThrownBy( assertThatIllegalArgumentException().isThrownBy(() ->
() -> databasePopulator.setScripts((Resource) null)); databasePopulator.setScripts((Resource) null));
} }
@Test @Test
public void setScriptsWithNullResourceArray() { void setScriptsWithNullResourceArray() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
assertThatIllegalArgumentException().isThrownBy( assertThatIllegalArgumentException().isThrownBy(() ->
() -> databasePopulator.setScripts((Resource[]) null)); databasePopulator.setScripts((Resource[]) null));
} }
@Test @Test
public void setScriptsAndThenAddScript() { void setScriptsAndThenAddScript() {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
assertThat(databasePopulator.scripts).isEmpty(); assertThat(databasePopulator.scripts).isEmpty();

View File

@ -1 +0,0 @@
INSERT INTO users(first_name, last_name) values('Walter', 'White');