diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorUnitTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorTests.java similarity index 95% rename from spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorUnitTests.java rename to spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorTests.java index fdeca7971a5..17d125dbb04 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorUnitTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorTests.java @@ -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. @@ -25,13 +25,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.mockito.BDDMockito.mock; /** - * Unit tests for {@link ResourceDatabasePopulator}. + * Tests for {@link ResourceDatabasePopulator}. * * @author Sam Brannen * @since 4.1 * @see AbstractDatabasePopulatorTests */ -class ResourceDatabasePopulatorUnitTests { +class ResourceDatabasePopulatorTests { private static final Resource script1 = mock(); private static final Resource script2 = mock(); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsIntegrationTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsIntegrationTests.java index 63590189c69..df8a9ccd7fc 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsIntegrationTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsIntegrationTests.java @@ -30,7 +30,7 @@ import static org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScr * * @author Sam Brannen * @since 4.0.3 - * @see ScriptUtilsUnitTests + * @see ScriptUtilsTests */ class ScriptUtilsIntegrationTests extends AbstractDatabaseInitializationTests { diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsUnitTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsTests.java similarity index 98% rename from spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsUnitTests.java rename to spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsTests.java index 6d861a0dce9..1872fbe522d 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsUnitTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsTests.java @@ -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. @@ -36,7 +36,7 @@ import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_COMME import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_STATEMENT_SEPARATOR; /** - * Unit tests for {@link ScriptUtils}. + * Tests for {@link ScriptUtils}. * * @author Thomas Risberg * @author Sam Brannen @@ -46,7 +46,7 @@ import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_STATE * @since 4.0.3 * @see ScriptUtilsIntegrationTests */ -class ScriptUtilsUnitTests { +class ScriptUtilsTests { @Test void splitSqlScriptDelimitedWithSemicolon() { diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBeanTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBeanTests.java index de630d73e7d..72151e38f9b 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBeanTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBeanTests.java @@ -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. @@ -45,7 +45,7 @@ public abstract class AbstractEntityManagerFactoryBeanTests { } @AfterEach - public void tearDown() { + void tearDown() { assertThat(TransactionSynchronizationManager.getResourceMap()).isEmpty(); assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse(); assertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse(); diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java index e6e91b1d2fd..04a10fd1d25 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java @@ -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. @@ -104,7 +104,7 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests { } @AfterEach - public void cleanup() { + void cleanup() { if (this.transactionStatus != null && !this.transactionStatus.isCompleted()) { endTransaction(); } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/JpaTransactionManagerTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/JpaTransactionManagerTests.java index 5a4f57c4e74..9fcb07b8b61 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/JpaTransactionManagerTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/JpaTransactionManagerTests.java @@ -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. @@ -71,7 +71,7 @@ class JpaTransactionManagerTests { } @AfterEach - public void verifyTransactionSynchronizationManagerState() { + void verifyTransactionSynchronizationManagerState() { assertThat(TransactionSynchronizationManager.getResourceMap()).isEmpty(); assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse(); assertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse(); diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBeanTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBeanTests.java index 10331d94f8c..81e2125b5db 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBeanTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBeanTests.java @@ -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. @@ -43,7 +43,7 @@ class LocalEntityManagerFactoryBeanTests extends AbstractEntityManagerFactoryBea private static Map actualProps; @AfterEach - public void verifyClosed() { + void verifyClosed() { verify(mockEmf).close(); } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/support/OpenEntityManagerInViewTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/support/OpenEntityManagerInViewTests.java index 10a0ffef26a..0cbd34cb263 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/support/OpenEntityManagerInViewTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/support/OpenEntityManagerInViewTests.java @@ -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. @@ -82,7 +82,7 @@ class OpenEntityManagerInViewTests { } @AfterEach - public void tearDown() { + void tearDown() { assertThat(TransactionSynchronizationManager.getResourceMap()).isEmpty(); assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse(); assertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse(); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/ConnectionFactoryUtilsUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/ConnectionFactoryUtilsTests.java similarity index 97% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/ConnectionFactoryUtilsUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/ConnectionFactoryUtilsTests.java index 62684756118..9f230baba87 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/ConnectionFactoryUtilsUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/ConnectionFactoryUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-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. @@ -40,12 +40,12 @@ import org.springframework.r2dbc.UncategorizedR2dbcException; import static org.assertj.core.api.Assertions.assertThat; /** - * Unit tests for {@link ConnectionFactoryUtils}. + * Tests for {@link ConnectionFactoryUtils}. * * @author Mark Paluch * @author Juergen Hoeller */ -class ConnectionFactoryUtilsUnitTests { +class ConnectionFactoryUtilsTests { @Test void shouldTranslateTransientResourceException() { diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryTests.java similarity index 91% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryTests.java index d02c0ffa66e..8f120de9e43 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryTests.java @@ -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. @@ -26,11 +26,11 @@ import static org.mockito.BDDMockito.mock; import static org.mockito.BDDMockito.when; /** - * Unit tests for {@link DelegatingConnectionFactory}. + * Tests for {@link DelegatingConnectionFactory}. * * @author Mark Paluch */ -class DelegatingConnectionFactoryUnitTests { +class DelegatingConnectionFactoryTests { ConnectionFactory delegate = mock(); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerTests.java similarity index 99% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerTests.java index 6a9bda3e8eb..040c4359cbe 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerTests.java @@ -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. @@ -55,12 +55,12 @@ import static org.mockito.BDDMockito.verifyNoMoreInteractions; import static org.mockito.BDDMockito.when; /** - * Unit tests for {@link R2dbcTransactionManager}. + * Tests for {@link R2dbcTransactionManager}. * * @author Mark Paluch * @author Juergen Hoeller */ -class R2dbcTransactionManagerUnitTests { +class R2dbcTransactionManagerTests { ConnectionFactory connectionFactoryMock = mock(); @@ -624,7 +624,7 @@ class R2dbcTransactionManagerUnitTests { private static class TestTransactionSynchronization implements TransactionSynchronization { - private int status; + private final int status; public boolean beforeCommitCalled; diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryTests.java similarity index 96% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryTests.java index dec679b7649..a445abe3ce2 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryTests.java @@ -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. @@ -33,11 +33,11 @@ import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; /** - * Unit tests for {@link SingleConnectionFactory}. + * Tests for {@link SingleConnectionFactory}. * * @author Mark Paluch */ -class SingleConnectionFactoryUnitTests { +class SingleConnectionFactoryTests { @Test void shouldAllocateSameConnection() { diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyTests.java similarity index 96% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyTests.java index f31192e23e9..fec9fbe626d 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyTests.java @@ -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. @@ -38,12 +38,12 @@ import static org.mockito.BDDMockito.verifyNoInteractions; import static org.mockito.BDDMockito.when; /** - * Unit tests for {@link TransactionAwareConnectionFactoryProxy}. + * Tests for {@link TransactionAwareConnectionFactoryProxy}. * * @author Mark Paluch * @author Christoph Strobl */ -class TransactionAwareConnectionFactoryProxyUnitTests { +class TransactionAwareConnectionFactoryProxyTests { ConnectionFactory connectionFactoryMock = mock(); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ConnectionFactoryInitializerUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ConnectionFactoryInitializerTests.java similarity index 93% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ConnectionFactoryInitializerUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ConnectionFactoryInitializerTests.java index 5d4d584a819..5e79730624a 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ConnectionFactoryInitializerUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ConnectionFactoryInitializerTests.java @@ -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. @@ -28,11 +28,11 @@ import static org.mockito.BDDMockito.mock; import static org.mockito.BDDMockito.when; /** - * Unit tests for {@link ConnectionFactoryInitializer}. + * Tests for {@link ConnectionFactoryInitializer}. * * @author Mark Paluch */ -class ConnectionFactoryInitializerUnitTests { +class ConnectionFactoryInitializerTests { AtomicBoolean called = new AtomicBoolean(); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulatorUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulatorTests.java similarity index 95% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulatorUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulatorTests.java index 8773f5f9a73..eaf39d60c87 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulatorUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulatorTests.java @@ -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. @@ -25,12 +25,12 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.mockito.BDDMockito.mock; /** - * Unit tests for {@link ResourceDatabasePopulator}. + * Tests for {@link ResourceDatabasePopulator}. * * @author Sam Brannen * @author Mark Paluch */ -class ResourceDatabasePopulatorUnitTests { +class ResourceDatabasePopulatorTests { private static final Resource script1 = mock(); private static final Resource script2 = mock(); 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/ScriptUtilsTests.java similarity index 93% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ScriptUtilsUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ScriptUtilsTests.java index 41dd48477d9..d62591859df 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/ScriptUtilsTests.java @@ -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. @@ -34,7 +34,7 @@ import static org.springframework.r2dbc.connection.init.ScriptUtils.DEFAULT_COMM import static org.springframework.r2dbc.connection.init.ScriptUtils.DEFAULT_STATEMENT_SEPARATOR; /** - * Unit tests for {@link ScriptUtils}. + * Tests for {@link ScriptUtils}. * * @author Thomas Risberg * @author Sam Brannen @@ -44,10 +44,10 @@ import static org.springframework.r2dbc.connection.init.ScriptUtils.DEFAULT_STAT * @author Mark Paluch * @since 5.3 */ -public class ScriptUtilsUnitTests { +class ScriptUtilsTests { @Test - public void splitSqlScriptDelimitedWithSemicolon() { + void splitSqlScriptDelimitedWithSemicolon() { String rawStatement1 = "insert into customer (id, name)\nvalues (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')"; String cleanedStatement1 = "insert into customer (id, name) values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')"; String rawStatement2 = "insert into orders(id, order_date, customer_id)\nvalues (1, '2008-01-02', 2)"; @@ -64,7 +64,7 @@ public class ScriptUtilsUnitTests { } @Test - public void splitSqlScriptDelimitedWithNewLine() { + void splitSqlScriptDelimitedWithNewLine() { String statement1 = "insert into customer (id, name) values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')"; String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)"; String statement3 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)"; @@ -78,7 +78,7 @@ public class ScriptUtilsUnitTests { } @Test - public void splitSqlScriptDelimitedWithNewLineButDefaultDelimiterSpecified() { + void splitSqlScriptDelimitedWithNewLineButDefaultDelimiterSpecified() { String statement1 = "do something"; String statement2 = "do something else"; @@ -103,7 +103,7 @@ public class ScriptUtilsUnitTests { } @Test // SPR-11560 - public void readAndSplitScriptWithMultipleNewlinesAsSeparator() throws Exception { + public void readAndSplitScriptWithMultipleNewlinesAsSeparator() { String script = readScript("db-test-data-multi-newline.sql"); List statements = splitSqlScript(script, "\n\n"); @@ -114,19 +114,19 @@ public class ScriptUtilsUnitTests { } @Test - public void readAndSplitScriptContainingComments() throws Exception { + void readAndSplitScriptContainingComments() { String script = readScript("test-data-with-comments.sql"); splitScriptContainingComments(script, DEFAULT_COMMENT_PREFIXES); } @Test - public void readAndSplitScriptContainingCommentsWithWindowsLineEnding() throws Exception { + void readAndSplitScriptContainingCommentsWithWindowsLineEnding() { String script = readScript("test-data-with-comments.sql").replaceAll("\n", "\r\n"); splitScriptContainingComments(script, DEFAULT_COMMENT_PREFIXES); } @Test - public void readAndSplitScriptContainingCommentsWithMultiplePrefixes() throws Exception { + void readAndSplitScriptContainingCommentsWithMultiplePrefixes() { String script = readScript("test-data-with-multi-prefix-comments.sql"); splitScriptContainingComments(script, "--", "#", "^"); } @@ -145,7 +145,7 @@ public class ScriptUtilsUnitTests { } @Test // SPR-10330 - public void readAndSplitScriptContainingCommentsWithLeadingTabs() throws Exception { + public void readAndSplitScriptContainingCommentsWithLeadingTabs() { String script = readScript("test-data-with-comments-and-leading-tabs.sql"); List statements = splitSqlScript(script, ";"); @@ -157,7 +157,7 @@ public class ScriptUtilsUnitTests { } @Test // SPR-9531 - public void readAndSplitScriptContainingMultiLineComments() throws Exception { + public void readAndSplitScriptContainingMultiLineComments() { String script = readScript("test-data-with-multi-line-comments.sql"); List statements = splitSqlScript(script, ";"); @@ -168,7 +168,7 @@ public class ScriptUtilsUnitTests { } @Test - public void readAndSplitScriptContainingMultiLineNestedComments() throws Exception { + void readAndSplitScriptContainingMultiLineNestedComments() { String script = readScript("test-data-with-multi-line-nested-comments.sql"); List statements = splitSqlScript(script, ";"); 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/AbstractRoutingConnectionFactoryTests.java similarity index 97% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactoryUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactoryTests.java index f07a9fc8a74..95986338773 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/AbstractRoutingConnectionFactoryTests.java @@ -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. @@ -32,13 +32,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.assertj.core.api.Assertions.assertThatThrownBy; /** - * Unit tests for {@link AbstractRoutingConnectionFactory}. + * Tests for {@link AbstractRoutingConnectionFactory}. * * @author Mark Paluch * @author Jens Schauder */ @ExtendWith(MockitoExtension.class) -class AbstractRoutingConnectionFactoryUnitTests { +class AbstractRoutingConnectionFactoryTests { private static final String ROUTING_KEY = "routingKey"; 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/BeanFactoryConnectionFactoryLookupTests.java similarity index 88% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/BeanFactoryConnectionFactoryLookupUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/BeanFactoryConnectionFactoryLookupTests.java index 2ccb13cb977..9674fd77d2e 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/BeanFactoryConnectionFactoryLookupTests.java @@ -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. @@ -32,12 +32,12 @@ import static org.mockito.BDDMockito.mock; import static org.mockito.BDDMockito.when; /** - * Unit tests for {@link BeanFactoryConnectionFactoryLookup}. + * Tests for {@link BeanFactoryConnectionFactoryLookup}. * * @author Mark Paluch */ @ExtendWith(MockitoExtension.class) -public class BeanFactoryConnectionFactoryLookupUnitTests { +public class BeanFactoryConnectionFactoryLookupTests { private static final String CONNECTION_FACTORY_BEAN_NAME = "connectionFactory"; @@ -46,7 +46,7 @@ public class BeanFactoryConnectionFactoryLookupUnitTests { @Test - public void shouldLookupConnectionFactory() { + void shouldLookupConnectionFactory() { DummyConnectionFactory expectedConnectionFactory = new DummyConnectionFactory(); when(beanFactory.getBean(CONNECTION_FACTORY_BEAN_NAME, ConnectionFactory.class)) .thenReturn(expectedConnectionFactory); @@ -60,7 +60,7 @@ public class BeanFactoryConnectionFactoryLookupUnitTests { } @Test - public void shouldLookupWhereBeanFactoryYieldsNonConnectionFactoryType() { + void shouldLookupWhereBeanFactoryYieldsNonConnectionFactoryType() { BeanFactory beanFactory = mock(); when(beanFactory.getBean(CONNECTION_FACTORY_BEAN_NAME, ConnectionFactory.class)) .thenThrow(new BeanNotOfRequiredTypeException( @@ -72,7 +72,7 @@ public class BeanFactoryConnectionFactoryLookupUnitTests { } @Test - public void shouldLookupWhereBeanFactoryHasNotBeenSupplied() { + void shouldLookupWhereBeanFactoryHasNotBeenSupplied() { BeanFactoryConnectionFactoryLookup lookup = new BeanFactoryConnectionFactoryLookup(); assertThatThrownBy(() -> lookup.getConnectionFactory(CONNECTION_FACTORY_BEAN_NAME)) 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/MapConnectionFactoryLookupTests.java similarity index 88% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/MapConnectionFactoryLookupUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/lookup/MapConnectionFactoryLookupTests.java index 40ac7940094..c81c7ca9a63 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/MapConnectionFactoryLookupTests.java @@ -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. @@ -26,17 +26,17 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; /** - * Unit tests for {@link MapConnectionFactoryLookup}. + * Tests for {@link MapConnectionFactoryLookup}. * * @author Mark Paluch */ -public class MapConnectionFactoryLookupUnitTests { +class MapConnectionFactoryLookupTests { private static final String CONNECTION_FACTORY_NAME = "connectionFactory"; @Test - public void getConnectionFactoriesReturnsUnmodifiableMap() { + void getConnectionFactoriesReturnsUnmodifiableMap() { MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup(); Map connectionFactories = lookup.getConnectionFactories(); @@ -45,7 +45,7 @@ public class MapConnectionFactoryLookupUnitTests { } @Test - public void shouldLookupConnectionFactory() { + void shouldLookupConnectionFactory() { Map connectionFactories = new HashMap<>(); DummyConnectionFactory expectedConnectionFactory = new DummyConnectionFactory(); connectionFactories.put(CONNECTION_FACTORY_NAME, expectedConnectionFactory); @@ -58,7 +58,7 @@ public class MapConnectionFactoryLookupUnitTests { } @Test - public void addingConnectionFactoryPermitsOverride() { + void addingConnectionFactoryPermitsOverride() { Map connectionFactories = new HashMap<>(); DummyConnectionFactory overriddenConnectionFactory = new DummyConnectionFactory(); DummyConnectionFactory expectedConnectionFactory = new DummyConnectionFactory(); @@ -84,7 +84,7 @@ public class MapConnectionFactoryLookupUnitTests { } @Test - public void getConnectionFactoryWhereSuppliedMapHasNoEntryForSpecifiedKey() { + void getConnectionFactoryWhereSuppliedMapHasNoEntryForSpecifiedKey() { MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup(); assertThatThrownBy( 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 7fdde3c3bea..d0625b1bcc0 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-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. @@ -76,7 +76,7 @@ abstract class AbstractDatabaseClientIntegrationTests { @Test - public void executeInsert() { + void executeInsert() { DatabaseClient databaseClient = DatabaseClient.create(connectionFactory); databaseClient.sql("INSERT INTO legoset (id, name, manual) VALUES(:id, :name, :manual)") @@ -97,7 +97,7 @@ abstract class AbstractDatabaseClientIntegrationTests { } @Test - public void executeInsertWithMap() { + void executeInsertWithMap() { DatabaseClient databaseClient = DatabaseClient.create(connectionFactory); databaseClient.sql("INSERT INTO legoset (id, name, manual) VALUES(:id, :name, :manual)") @@ -118,7 +118,7 @@ abstract class AbstractDatabaseClientIntegrationTests { } @Test - public void executeInsertWithRecords() { + void executeInsertWithRecords() { DatabaseClient databaseClient = DatabaseClient.create(connectionFactory); databaseClient.sql("INSERT INTO legoset (id, name, manual) VALUES(:id, :name, :manual)") @@ -137,7 +137,7 @@ abstract class AbstractDatabaseClientIntegrationTests { } @Test - public void shouldTranslateDuplicateKeyException() { + void shouldTranslateDuplicateKeyException() { DatabaseClient databaseClient = DatabaseClient.create(connectionFactory); executeInsert(); @@ -156,7 +156,7 @@ abstract class AbstractDatabaseClientIntegrationTests { } @Test - public void executeDeferred() { + void executeDeferred() { DatabaseClient databaseClient = DatabaseClient.create(connectionFactory); databaseClient.sql(() -> "INSERT INTO legoset (id, name, manual) VALUES(:id, :name, :manual)") @@ -176,7 +176,7 @@ abstract class AbstractDatabaseClientIntegrationTests { } @Test - public void shouldEmitGeneratedKey() { + void shouldEmitGeneratedKey() { DatabaseClient databaseClient = DatabaseClient.create(connectionFactory); databaseClient.sql( 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 c8abd3083c2..e1cf24c1d88 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 @@ -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. @@ -111,7 +111,7 @@ abstract class AbstractTransactionalDatabaseClientIntegrationTests { @Test - public void executeInsertInTransaction() { + void executeInsertInTransaction() { Flux longFlux = databaseClient .sql(getInsertIntoLegosetStatement()) .bind(0, 42055) @@ -133,7 +133,7 @@ abstract class AbstractTransactionalDatabaseClientIntegrationTests { } @Test - public void shouldRollbackTransaction() { + void shouldRollbackTransaction() { Mono integerFlux = databaseClient.sql(getInsertIntoLegosetStatement()) .bind(0, 42055) .bind(1, "SCHAUFELRADBAGGER") @@ -155,7 +155,7 @@ abstract class AbstractTransactionalDatabaseClientIntegrationTests { } @Test - public void shouldRollbackTransactionUsingTransactionalOperator() { + void shouldRollbackTransactionUsingTransactionalOperator() { DatabaseClient databaseClient = DatabaseClient.create(connectionFactory); TransactionalOperator transactionalOperator = TransactionalOperator diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientTests.java similarity index 97% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientTests.java index 5afcb3670c0..93f9a65d97f 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientTests.java @@ -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. @@ -60,7 +60,7 @@ import static org.mockito.BDDMockito.verifyNoMoreInteractions; import static org.mockito.BDDMockito.when; /** - * Unit tests for {@link DefaultDatabaseClient}. + * Tests for {@link DefaultDatabaseClient}. * * @author Mark Paluch * @author Ferdinand Jacobs @@ -68,7 +68,7 @@ import static org.mockito.BDDMockito.when; * @author Simon Baslé */ @MockitoSettings(strictness = Strictness.LENIENT) -class DefaultDatabaseClientUnitTests { +class DefaultDatabaseClientTests { @Mock private Connection connection; @@ -499,21 +499,9 @@ class DefaultDatabaseClientUnitTests { } - static class ParameterBean { + record ParameterBean(String key) {} - private final String key; - public ParameterBean(String key) { - this.key = key; - } - - public String getKey() { - return key; - } - } - - - record ParameterRecord(String key) { - } + record ParameterRecord(String key) {} } diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/H2DatabaseClientContextIntegrationTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/H2DatabaseClientContextIntegrationTests.java index 133c15204cf..61f60492c7b 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/H2DatabaseClientContextIntegrationTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/H2DatabaseClientContextIntegrationTests.java @@ -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. @@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Juergen Hoeller * @since 6.1 */ -public class H2DatabaseClientContextIntegrationTests extends H2DatabaseClientIntegrationTests { +class H2DatabaseClientContextIntegrationTests extends H2DatabaseClientIntegrationTests { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); 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 de21582c0d4..a4fb2672c2e 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-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. @@ -24,7 +24,7 @@ import io.r2dbc.spi.ConnectionFactory; * * @author Mark Paluch */ -public class H2DatabaseClientIntegrationTests extends AbstractDatabaseClientIntegrationTests { +class H2DatabaseClientIntegrationTests extends AbstractDatabaseClientIntegrationTests { private static final String CREATE_TABLE_LEGOSET = """ CREATE TABLE legoset ( 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 bf3e567d2ba..7c0dee82920 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-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. @@ -24,7 +24,7 @@ import io.r2dbc.spi.ConnectionFactory; * * @author Mark Paluch */ -public class H2TransactionalDatabaseClientIntegrationTests extends AbstractTransactionalDatabaseClientIntegrationTests { +class H2TransactionalDatabaseClientIntegrationTests extends AbstractTransactionalDatabaseClientIntegrationTests { private static final String CREATE_TABLE_LEGOSET = """ CREATE TABLE legoset ( diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsTests.java similarity index 90% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsTests.java index 8bb5d5eb537..139291ce91a 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsTests.java @@ -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. @@ -35,19 +35,19 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** - * Unit tests for {@link NamedParameterUtils}. + * Tests for {@link NamedParameterUtils}. * * @author Mark Paluch * @author Jens Schauder * @author Anton Naydenov */ -public class NamedParameterUtilsUnitTests { +class NamedParameterUtilsTests { private final BindMarkersFactory BIND_MARKERS = BindMarkersFactory.indexed("$", 1); @Test - public void shouldParseSql() { + void shouldParseSql() { String sql = "xxx :a yyyy :b :c :a zzzzz"; ParsedSql psql = NamedParameterUtils.parseSqlStatement(sql); assertThat(psql.getParameterNames()).containsExactly("a", "b", "c", "a"); @@ -66,7 +66,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void substituteNamedParameters() { + void substituteNamedParameters() { MapBindParameterSource namedParams = new MapBindParameterSource(new HashMap<>()); namedParams.addValue("a", "a").addValue("b", "b").addValue("c", "c"); @@ -82,7 +82,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void substituteObjectArray() { + void substituteObjectArray() { MapBindParameterSource namedParams = new MapBindParameterSource(new HashMap<>()); namedParams.addValue("a", Arrays.asList(new Object[] {"Walter", "Heisenberg"}, @@ -95,7 +95,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void shouldBindObjectArray() { + void shouldBindObjectArray() { MapBindParameterSource namedParams = new MapBindParameterSource(new HashMap<>()); namedParams.addValue("a", Arrays.asList(new Object[] {"Walter", "Heisenberg"}, @@ -114,7 +114,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void parseSqlContainingComments() { + void parseSqlContainingComments() { String sql1 = "/*+ HINT */ xxx /* comment ? */ :a yyyy :b :c :a zzzzz -- :xx XX\n"; ParsedSql psql1 = NamedParameterUtils.parseSqlStatement(sql1); @@ -133,7 +133,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void parseSqlStatementWithPostgresCasting() { + void parseSqlStatementWithPostgresCasting() { String expectedSql = "select 'first name' from artists where id = $1 and birth_date=$2::timestamp"; String sql = "select 'first name' from artists where id = :id and birth_date=:birthDate::timestamp"; @@ -145,7 +145,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void parseSqlStatementWithPostgresContainedOperator() { + void parseSqlStatementWithPostgresContainedOperator() { String expectedSql = "select 'first name' from artists where info->'stat'->'albums' = ?? $1 and '[\"1\",\"2\",\"3\"]'::jsonb ?? '4'"; String sql = "select 'first name' from artists where info->'stat'->'albums' = ?? :album and '[\"1\",\"2\",\"3\"]'::jsonb ?? '4'"; @@ -155,7 +155,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void parseSqlStatementWithPostgresAnyArrayStringsExistsOperator() { + void parseSqlStatementWithPostgresAnyArrayStringsExistsOperator() { String expectedSql = "select '[\"3\", \"11\"]'::jsonb ?| '{1,3,11,12,17}'::text[]"; String sql = "select '[\"3\", \"11\"]'::jsonb ?| '{1,3,11,12,17}'::text[]"; @@ -165,7 +165,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void parseSqlStatementWithPostgresAllArrayStringsExistsOperator() { + void parseSqlStatementWithPostgresAllArrayStringsExistsOperator() { String expectedSql = "select '[\"3\", \"11\"]'::jsonb ?& '{1,3,11,12,17}'::text[] AND $1 = 'Back in Black'"; String sql = "select '[\"3\", \"11\"]'::jsonb ?& '{1,3,11,12,17}'::text[] AND :album = 'Back in Black'"; @@ -175,7 +175,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void parseSqlStatementWithEscapedColon() { + void parseSqlStatementWithEscapedColon() { String expectedSql = "select '0\\:0' as a, foo from bar where baz < DATE($1 23:59:59) and baz = $2"; String sql = "select '0\\:0' as a, foo from bar where baz < DATE(:p1 23\\:59\\:59) and baz = :p2"; @@ -185,7 +185,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void parseSqlStatementWithBracketDelimitedParameterNames() { + void parseSqlStatementWithBracketDelimitedParameterNames() { String expectedSql = "select foo from bar where baz = b$1$2z"; String sql = "select foo from bar where baz = b:{p1}:{p2}z"; @@ -195,7 +195,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void parseSqlStatementWithEmptyBracketsOrBracketsInQuotes() { + void parseSqlStatementWithEmptyBracketsOrBracketsInQuotes() { String expectedSql = "select foo from bar where baz = b:{}z"; String sql = "select foo from bar where baz = b:{}z"; @@ -212,7 +212,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void parseSqlStatementWithSingleLetterInBrackets() { + void parseSqlStatementWithSingleLetterInBrackets() { String expectedSql = "select foo from bar where baz = b$1z"; String sql = "select foo from bar where baz = b:{p}z"; @@ -222,7 +222,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void parseSqlStatementWithLogicalAnd() { + void parseSqlStatementWithLogicalAnd() { String expectedSql = "xxx & yyyy"; ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(expectedSql); @@ -230,21 +230,21 @@ public class NamedParameterUtilsUnitTests { } @Test - public void substituteNamedParametersWithLogicalAnd() { + void substituteNamedParametersWithLogicalAnd() { String expectedSql = "xxx & yyyy"; assertThat(expand(expectedSql)).isEqualTo(expectedSql); } @Test - public void variableAssignmentOperator() { + void variableAssignmentOperator() { String expectedSql = "x := 1"; assertThat(expand(expectedSql)).isEqualTo(expectedSql); } @Test - public void parseSqlStatementWithQuotedSingleQuote() { + void parseSqlStatementWithQuotedSingleQuote() { String sql = "SELECT ':foo'':doo', :xxx FROM DUAL"; ParsedSql psql = NamedParameterUtils.parseSqlStatement(sql); @@ -253,7 +253,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void parseSqlStatementWithQuotesAndCommentBefore() { + void parseSqlStatementWithQuotesAndCommentBefore() { String sql = "SELECT /*:doo*/':foo', :xxx FROM DUAL"; ParsedSql psql = NamedParameterUtils.parseSqlStatement(sql); @@ -262,7 +262,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void parseSqlStatementWithQuotesAndCommentAfter() { + void parseSqlStatementWithQuotesAndCommentAfter() { String sql2 = "SELECT ':foo'/*:doo*/, :xxx FROM DUAL"; ParsedSql psql2 = NamedParameterUtils.parseSqlStatement(sql2); @@ -288,7 +288,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void shouldAllowParsingMultipleUseOfParameter() { + void shouldAllowParsingMultipleUseOfParameter() { String sql = "SELECT * FROM person where name = :id or lastname = :id"; ParsedSql parsed = NamedParameterUtils.parseSqlStatement(sql); @@ -298,7 +298,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void multipleEqualParameterReferencesBindsValueOnce() { + void multipleEqualParameterReferencesBindsValueOnce() { String sql = "SELECT * FROM person where name = :id or lastname = :id"; BindMarkersFactory factory = BindMarkersFactory.indexed("$", 0); @@ -332,7 +332,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void multipleEqualCollectionParameterReferencesBindsValueOnce() { + void multipleEqualCollectionParameterReferencesBindsValueOnce() { String sql = "SELECT * FROM person where name IN (:ids) or lastname IN (:ids)"; BindMarkersFactory factory = BindMarkersFactory.indexed("$", 0); @@ -373,7 +373,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void multipleEqualParameterReferencesForAnonymousMarkersBindsValueMultipleTimes() { + void multipleEqualParameterReferencesForAnonymousMarkersBindsValueMultipleTimes() { String sql = "SELECT * FROM person where name = :id or lastname = :id"; BindMarkersFactory factory = BindMarkersFactory.anonymous("?"); @@ -410,7 +410,7 @@ public class NamedParameterUtilsUnitTests { } @Test - public void multipleEqualParameterReferencesBindsNullOnce() { + void multipleEqualParameterReferencesBindsNullOnce() { String sql = "SELECT * FROM person where name = :id or lastname = :id"; BindMarkersFactory factory = BindMarkersFactory.indexed("$", 0); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/R2dbcBeanPropertyRowMapperTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/R2dbcBeanPropertyRowMapperTests.java index f8c3acaf5e5..192b9f655b1 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/R2dbcBeanPropertyRowMapperTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/R2dbcBeanPropertyRowMapperTests.java @@ -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. @@ -57,10 +57,9 @@ class R2dbcBeanPropertyRowMapperTests { @Test void mappingRowSimpleObject() { - MockRow mockRow = SIMPLE_PERSON_ROW; BeanPropertyRowMapper mapper = new BeanPropertyRowMapper<>(Person.class); - Person result = mapper.apply(mockRow); + Person result = mapper.apply(SIMPLE_PERSON_ROW); assertThat(result.firstName).as("firstName").isEqualTo("John"); assertThat(result.lastName).as("lastName").isEqualTo("Doe"); @@ -69,10 +68,9 @@ class R2dbcBeanPropertyRowMapperTests { @Test void mappingRowMissingAttributeAccepted() { - MockRow mockRow = SIMPLE_PERSON_ROW; BeanPropertyRowMapper mapper = new BeanPropertyRowMapper<>(ExtendedPerson.class); - ExtendedPerson result = mapper.apply(mockRow); + ExtendedPerson result = mapper.apply(SIMPLE_PERSON_ROW); assertThat(result.firstName).as("firstName").isEqualTo("John"); assertThat(result.lastName).as("lastName").isEqualTo("Doe"); @@ -82,10 +80,9 @@ class R2dbcBeanPropertyRowMapperTests { @Test void mappingRowWithDifferentName() { - MockRow mockRow = EMAIL_PERSON_ROW; BeanPropertyRowMapper mapper = new BeanPropertyRowMapper<>(EmailPerson.class); - EmailPerson result = mapper.apply(mockRow); + EmailPerson result = mapper.apply(EMAIL_PERSON_ROW); assertThat(result.firstName).as("firstName").isEqualTo("John"); assertThat(result.lastName).as("lastName").isEqualTo("Doe"); @@ -95,11 +92,10 @@ class R2dbcBeanPropertyRowMapperTests { @Test void rowTypeAndMappingTypeMisaligned() { - MockRow mockRow = EXTENDED_PERSON_ROW; BeanPropertyRowMapper mapper = new BeanPropertyRowMapper<>(TypeMismatchExtendedPerson.class); assertThatExceptionOfType(TypeMismatchException.class) - .isThrownBy(() -> mapper.apply(mockRow)) + .isThrownBy(() -> mapper.apply(EXTENDED_PERSON_ROW)) .withMessage("Failed to convert property value of type 'java.lang.String' to required type " + "'java.lang.String' for property 'address'; simulating type mismatch for address"); } diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/R2dbcDataClassRowMapperTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/R2dbcDataClassRowMapperTests.java index 74532a7e4b5..9e626649605 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/R2dbcDataClassRowMapperTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/R2dbcDataClassRowMapperTests.java @@ -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. @@ -38,10 +38,10 @@ class R2dbcDataClassRowMapperTests { @Test void staticQueryWithDataClass() { - MockRow mockRow = MOCK_ROW; // uses name, age, birth_date DataClassRowMapper mapper = new DataClassRowMapper<>(ConstructorPerson.class); - ConstructorPerson person = mapper.apply(mockRow); + // uses name, age, birth_date + ConstructorPerson person = mapper.apply(MOCK_ROW); assertThat(person.name).as("name").isEqualTo("Bubba"); assertThat(person.age).as("age").isEqualTo(22L); @@ -63,9 +63,10 @@ class R2dbcDataClassRowMapperTests { @Test void staticQueryWithDataRecord() { - MockRow mockRow = MOCK_ROW; // uses name, age, birth_date, balance DataClassRowMapper mapper = new DataClassRowMapper<>(RecordPerson.class); - RecordPerson person = mapper.apply(mockRow); + + // uses name, age, birth_date, balance + RecordPerson person = mapper.apply(MOCK_ROW); assertThat(person.name()).isEqualTo("Bubba"); assertThat(person.age()).isEqualTo(22L); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/AnonymousBindMarkersUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/AnonymousBindMarkersTests.java similarity index 87% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/AnonymousBindMarkersUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/AnonymousBindMarkersTests.java index b609b0429a5..a65bde62169 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/AnonymousBindMarkersUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/AnonymousBindMarkersTests.java @@ -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. @@ -23,14 +23,14 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** - * Unit tests for {@link AnonymousBindMarkers}. + * Tests for {@link AnonymousBindMarkers}. * * @author Mark Paluch */ -class AnonymousBindMarkersUnitTests { +class AnonymousBindMarkersTests { @Test - public void shouldCreateNewBindMarkers() { + void shouldCreateNewBindMarkers() { BindMarkersFactory factory = BindMarkersFactory.anonymous("?"); BindMarkers bindMarkers1 = factory.create(); @@ -41,7 +41,7 @@ class AnonymousBindMarkersUnitTests { } @Test - public void shouldBindByIndex() { + void shouldBindByIndex() { BindTarget bindTarget = mock(); BindMarkers bindMarkers = BindMarkersFactory.anonymous("?").create(); 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/BindMarkersFactoryResolverTests.java similarity index 94% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/BindMarkersFactoryResolverUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/BindMarkersFactoryResolverTests.java index 85fb67bbb5c..7e310e34def 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/BindMarkersFactoryResolverTests.java @@ -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. @@ -25,11 +25,11 @@ import org.reactivestreams.Publisher; import static org.assertj.core.api.Assertions.assertThat; /** - * Unit tests for {@link BindMarkersFactoryResolver}. + * Tests for {@link BindMarkersFactoryResolver}. * * @author Mark Paluch */ -class BindMarkersFactoryResolverUnitTests { +class BindMarkersFactoryResolverTests { @Test void shouldReturnBindMarkersFactoryForH2() { 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/BindingsTests.java similarity index 97% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/BindingsUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/BindingsTests.java index a5daced20ea..1d61a178117 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/BindingsTests.java @@ -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. @@ -27,11 +27,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** - * Unit tests for {@link Bindings}. + * Tests for {@link Bindings}. * * @author Mark Paluch */ -class BindingsUnitTests { +class BindingsTests { BindMarkersFactory markersFactory = BindMarkersFactory.indexed("$", 1); 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/IndexedBindMarkersTests.java similarity index 95% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/IndexedBindMarkersUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/IndexedBindMarkersTests.java index 21c4a3bb046..1da083cfd75 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/IndexedBindMarkersTests.java @@ -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. @@ -23,11 +23,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** - * Unit tests for {@link IndexedBindMarkers}. + * Tests for {@link IndexedBindMarkers}. * * @author Mark Paluch */ -class IndexedBindMarkersUnitTests { +class IndexedBindMarkersTests { @Test void shouldCreateNewBindMarkers() { 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/NamedBindMarkersTests.java similarity index 96% rename from spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/NamedBindMarkersUnitTests.java rename to spring-r2dbc/src/test/java/org/springframework/r2dbc/core/binding/NamedBindMarkersTests.java index 1cc4b7580f1..e5170bff7f7 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/NamedBindMarkersTests.java @@ -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. @@ -25,11 +25,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** - * Unit tests for {@link NamedBindMarkers}. + * Tests for {@link NamedBindMarkers}. * * @author Mark Paluch */ -class NamedBindMarkersUnitTests { +class NamedBindMarkersTests { @Test void shouldCreateNewBindMarkers() { diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorIntegrationTests.java new file mode 100644 index 00000000000..093e3614de7 --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorIntegrationTests.java @@ -0,0 +1,444 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.test.context.aot; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.stream.Stream; + +import javax.sql.DataSource; + +import org.junit.jupiter.api.Test; + +import org.springframework.aot.AotDetector; +import org.springframework.aot.generate.DefaultGenerationContext; +import org.springframework.aot.generate.GeneratedFiles.Kind; +import org.springframework.aot.generate.InMemoryGeneratedFiles; +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.TypeReference; +import org.springframework.aot.test.generate.CompilerFiles; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.test.tools.CompileWithForkedClassLoader; +import org.springframework.core.test.tools.TestCompiler; +import org.springframework.javapoet.ClassName; +import org.springframework.test.context.BootstrapUtils; +import org.springframework.test.context.MergedContextConfiguration; +import org.springframework.test.context.TestContextBootstrapper; +import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterSharedConfigTests; +import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests; +import org.springframework.test.context.aot.samples.basic.BasicSpringTestNGTests; +import org.springframework.test.context.aot.samples.basic.BasicSpringVintageTests; +import org.springframework.test.context.aot.samples.common.MessageService; +import org.springframework.test.context.aot.samples.jdbc.SqlScriptsSpringJupiterTests; +import org.springframework.test.context.aot.samples.web.WebSpringJupiterTests; +import org.springframework.test.context.aot.samples.web.WebSpringTestNGTests; +import org.springframework.test.context.aot.samples.web.WebSpringVintageTests; +import org.springframework.test.context.aot.samples.xml.XmlSpringJupiterTests; +import org.springframework.test.context.aot.samples.xml.XmlSpringTestNGTests; +import org.springframework.test.context.aot.samples.xml.XmlSpringVintageTests; +import org.springframework.test.context.env.YamlPropertySourceFactory; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.util.function.ThrowingConsumer; +import org.springframework.web.context.WebApplicationContext; + +import static java.util.Comparator.comparing; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.springframework.aot.hint.MemberCategory.INVOKE_DECLARED_CONSTRUCTORS; +import static org.springframework.aot.hint.MemberCategory.INVOKE_DECLARED_METHODS; +import static org.springframework.aot.hint.MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS; +import static org.springframework.aot.hint.MemberCategory.INVOKE_PUBLIC_METHODS; +import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.reflection; +import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.resource; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; + +/** + * Tests for {@link TestContextAotGenerator}, {@link AotTestContextInitializers}, + * {@link AotTestAttributes}, {@link AotContextLoader}, and run-time hints. + * + * @author Sam Brannen + * @since 6.0 + */ +@CompileWithForkedClassLoader +class TestContextAotGeneratorIntegrationTests extends AbstractAotTests { + + /** + * End-to-end tests within the scope of the {@link TestContextAotGenerator}. + * + * @see AotIntegrationTests + */ + @Test + void endToEndTests() { + Set> testClasses = Set.of( + BasicSpringJupiterSharedConfigTests.class, + BasicSpringJupiterTests.class, + BasicSpringJupiterTests.NestedTests.class, + BasicSpringTestNGTests.class, + BasicSpringVintageTests.class, + SqlScriptsSpringJupiterTests.class, + XmlSpringJupiterTests.class, + WebSpringJupiterTests.class); + + InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles(); + TestContextAotGenerator generator = new TestContextAotGenerator(generatedFiles); + + generator.processAheadOfTime(testClasses.stream().sorted(comparing(Class::getName))); + + assertRuntimeHints(generator.getRuntimeHints()); + + List sourceFiles = generatedFiles.getGeneratedFiles(Kind.SOURCE).keySet().stream().toList(); + assertThat(sourceFiles).containsExactlyInAnyOrder(expectedSourceFiles); + + TestCompiler.forSystem().with(CompilerFiles.from(generatedFiles)).compile(ThrowingConsumer.of(compiled -> { + try { + System.setProperty(AotDetector.AOT_ENABLED, "true"); + AotTestAttributesFactory.reset(); + AotTestContextInitializersFactory.reset(); + + AotTestAttributes aotAttributes = AotTestAttributes.getInstance(); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> aotAttributes.setAttribute("foo", "bar")) + .withMessage("AOT attributes cannot be modified during AOT run-time execution"); + String key = "@SpringBootConfiguration-" + BasicSpringVintageTests.class.getName(); + assertThat(aotAttributes.getString(key)).isEqualTo("org.example.Main"); + assertThat(aotAttributes.getBoolean(key + "-active1")).isTrue(); + assertThat(aotAttributes.getBoolean(key + "-active2")).isTrue(); + assertThat(aotAttributes.getString("bogus")).isNull(); + assertThat(aotAttributes.getBoolean("bogus")).isFalse(); + + AotTestContextInitializers aotContextInitializers = new AotTestContextInitializers(); + for (Class testClass : testClasses) { + MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); + ApplicationContextInitializer contextInitializer = + aotContextInitializers.getContextInitializer(testClass); + assertThat(contextInitializer).isNotNull(); + ApplicationContext context = ((AotContextLoader) mergedConfig.getContextLoader()) + .loadContextForAotRuntime(mergedConfig, contextInitializer); + if (context instanceof WebApplicationContext wac) { + assertContextForWebTests(wac); + } + else if (testClass.getPackageName().contains("jdbc")) { + assertContextForJdbcTests(context); + } + else { + assertContextForBasicTests(context); + } + } + } + finally { + System.clearProperty(AotDetector.AOT_ENABLED); + AotTestAttributesFactory.reset(); + } + })); + } + + private static void assertRuntimeHints(RuntimeHints runtimeHints) { + assertReflectionRegistered(runtimeHints, AotTestContextInitializersCodeGenerator.GENERATED_MAPPINGS_CLASS_NAME, INVOKE_PUBLIC_METHODS); + assertReflectionRegistered(runtimeHints, AotTestAttributesCodeGenerator.GENERATED_ATTRIBUTES_CLASS_NAME, INVOKE_PUBLIC_METHODS); + + Stream.of( + "org.opentest4j.TestAbortedException", + "org.junit.AssumptionViolatedException", + "org.testng.SkipException" + ).forEach(type -> assertReflectionRegistered(runtimeHints, type)); + + Stream.of( + org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.class, + org.springframework.test.context.support.DefaultBootstrapContext.class + ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_PUBLIC_CONSTRUCTORS)); + + Stream.of( + org.springframework.test.context.support.DefaultTestContextBootstrapper.class, + org.springframework.test.context.support.DelegatingSmartContextLoader.class, + org.springframework.test.context.support.GenericGroovyXmlContextLoader.class, + org.springframework.test.context.web.GenericGroovyXmlWebContextLoader.class, + org.springframework.test.context.web.WebDelegatingSmartContextLoader.class, + org.springframework.test.context.web.WebTestContextBootstrapper.class + ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS)); + + Stream.of( + org.springframework.test.context.web.WebAppConfiguration.class + ).forEach(type -> assertAnnotationRegistered(runtimeHints, type)); + + // TestExecutionListener + Stream.of( + // @TestExecutionListeners + org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests.DummyTestExecutionListener.class, + org.springframework.test.context.event.ApplicationEventsTestExecutionListener.class, + org.springframework.test.context.event.EventPublishingTestExecutionListener.class, + org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener.class, + org.springframework.test.context.support.DependencyInjectionTestExecutionListener.class, + org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener.class, + org.springframework.test.context.support.DirtiesContextTestExecutionListener.class, + org.springframework.test.context.transaction.TransactionalTestExecutionListener.class, + org.springframework.test.context.web.ServletTestExecutionListener.class + ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS)); + + // ContextCustomizerFactory + Stream.of( + "org.springframework.test.context.support.DynamicPropertiesContextCustomizerFactory", + "org.springframework.test.context.web.socket.MockServerContainerContextCustomizerFactory", + "org.springframework.test.context.aot.samples.basic.ImportsContextCustomizerFactory" + ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS)); + + Stream.of( + // @BootstrapWith + org.springframework.test.context.aot.samples.basic.BasicSpringVintageTests.CustomXmlBootstrapper.class, + // @ContextConfiguration(initializers = ...) + org.springframework.test.context.aot.samples.basic.BasicSpringTestNGTests.CustomInitializer.class, + // @ContextConfiguration(loader = ...) + org.springframework.test.context.support.AnnotationConfigContextLoader.class, + // @ActiveProfiles(resolver = ...) + org.springframework.test.context.aot.samples.basic.SpanishActiveProfilesResolver.class + ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS)); + + // @ContextConfiguration(locations = ...) + assertThat(resource().forResource("org/springframework/test/context/aot/samples/xml/test-config.xml")) + .accepts(runtimeHints); + + // @TestPropertySource(locations = ...) + assertThat(resource().forResource("org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.properties")) + .as("@TestPropertySource(locations)") + .accepts(runtimeHints); + + // @YamlTestProperties(...) + assertThat(resource().forResource("org/springframework/test/context/aot/samples/basic/test1.yaml")) + .as("@YamlTestProperties: test1.yaml") + .accepts(runtimeHints); + assertThat(resource().forResource("org/springframework/test/context/aot/samples/basic/test2.yaml")) + .as("@YamlTestProperties: test2.yaml") + .accepts(runtimeHints); + + // @TestPropertySource(factory = ...) + assertReflectionRegistered(runtimeHints, YamlPropertySourceFactory.class.getName(), INVOKE_DECLARED_CONSTRUCTORS); + + // @WebAppConfiguration(value = ...) + assertThat(resource().forResource("META-INF/web-resources/resources/Spring.js")).accepts(runtimeHints); + assertThat(resource().forResource("META-INF/web-resources/WEB-INF/views/home.jsp")).accepts(runtimeHints); + + // @Sql(scripts = ...) + assertThat(resource().forResource("org/springframework/test/context/jdbc/schema.sql")) + .accepts(runtimeHints); + assertThat(resource().forResource("org/springframework/test/context/aot/samples/jdbc/SqlScriptsSpringJupiterTests.test.sql")) + .accepts(runtimeHints); + } + + private static void assertReflectionRegistered(RuntimeHints runtimeHints, String type) { + assertThat(reflection().onType(TypeReference.of(type))) + .as("Reflection hint for %s", type) + .accepts(runtimeHints); + } + + private static void assertReflectionRegistered(RuntimeHints runtimeHints, String type, MemberCategory memberCategory) { + assertThat(reflection().onType(TypeReference.of(type)).withMemberCategory(memberCategory)) + .as("Reflection hint for %s with category %s", type, memberCategory) + .accepts(runtimeHints); + } + + private static void assertReflectionRegistered(RuntimeHints runtimeHints, Class type, MemberCategory memberCategory) { + assertThat(reflection().onType(type).withMemberCategory(memberCategory)) + .as("Reflection hint for %s with category %s", type.getSimpleName(), memberCategory) + .accepts(runtimeHints); + } + + private static void assertAnnotationRegistered(RuntimeHints runtimeHints, Class annotationType) { + assertReflectionRegistered(runtimeHints, annotationType, INVOKE_DECLARED_METHODS); + } + + + @Test + void processAheadOfTimeWithBasicTests() { + // We cannot parameterize with the test classes, since @CompileWithTargetClassAccess + // cannot support @ParameterizedTest methods. + Set> testClasses = Set.of( + BasicSpringJupiterSharedConfigTests.class, + BasicSpringJupiterTests.class, + BasicSpringJupiterTests.NestedTests.class, + BasicSpringTestNGTests.class, + BasicSpringVintageTests.class); + + processAheadOfTime(testClasses, this::assertContextForBasicTests); + } + + private void assertContextForBasicTests(ApplicationContext context) { + assertThat(context.getEnvironment().getProperty("test.engine")).as("Environment").isNotNull(); + + MessageService messageService = context.getBean(MessageService.class); + ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context; + String expectedMessage = cac.getEnvironment().matchesProfiles("spanish") ? + "¡Hola, AOT!" : "Hello, AOT!"; + assertThat(messageService.generateMessage()).isEqualTo(expectedMessage); + } + + private void assertContextForJdbcTests(ApplicationContext context) throws Exception { + assertThat(context.getEnvironment().getProperty("test.engine")).as("Environment").isNotNull(); + assertThat(context.getBean(DataSource.class)).as("DataSource").isNotNull(); + } + + private void assertContextForWebTests(WebApplicationContext wac) throws Exception { + assertThat(wac.getEnvironment().getProperty("test.engine")).as("Environment").isNotNull(); + + MockMvc mockMvc = webAppContextSetup(wac).build(); + mockMvc.perform(get("/hello")).andExpectAll(status().isOk(), content().string("Hello, AOT!")); + } + + @Test + void processAheadOfTimeWithXmlTests() { + // We cannot parameterize with the test classes, since @CompileWithTargetClassAccess + // cannot support @ParameterizedTest methods. + Set> testClasses = Set.of( + XmlSpringJupiterTests.class, + XmlSpringTestNGTests.class, + XmlSpringVintageTests.class); + + processAheadOfTime(testClasses, context -> { + assertThat(context.getEnvironment().getProperty("test.engine")) + .as("Environment").isNotNull(); + + MessageService messageService = context.getBean(MessageService.class); + assertThat(messageService.generateMessage()).isEqualTo("Hello, AOT!"); + }); + } + + @Test + void processAheadOfTimeWithWebTests() { + // We cannot parameterize with the test classes, since @CompileWithTargetClassAccess + // cannot support @ParameterizedTest methods. + Set> testClasses = Set.of( + WebSpringJupiterTests.class, + WebSpringTestNGTests.class, + WebSpringVintageTests.class); + + processAheadOfTime(testClasses, context -> { + assertThat(context.getEnvironment().getProperty("test.engine")) + .as("Environment").isNotNull(); + + MockMvc mockMvc = webAppContextSetup((WebApplicationContext) context).build(); + mockMvc.perform(get("/hello")) + .andExpectAll(status().isOk(), content().string("Hello, AOT!")); + }); + } + + + @SuppressWarnings("unchecked") + private void processAheadOfTime(Set> testClasses, ThrowingConsumer result) { + InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles(); + TestContextAotGenerator generator = new TestContextAotGenerator(generatedFiles); + List mappings = processAheadOfTime(generator, testClasses); + TestCompiler.forSystem().with(CompilerFiles.from(generatedFiles)).compile(ThrowingConsumer.of(compiled -> { + for (Mapping mapping : mappings) { + MergedContextConfiguration mergedConfig = mapping.mergedConfig(); + ApplicationContextInitializer contextInitializer = + compiled.getInstance(ApplicationContextInitializer.class, mapping.className().reflectionName()); + ApplicationContext context = ((AotContextLoader) mergedConfig.getContextLoader()) + .loadContextForAotRuntime(mergedConfig, contextInitializer); + result.accept(context); + } + })); + } + + private List processAheadOfTime(TestContextAotGenerator generator, Set> testClasses) { + List mappings = new ArrayList<>(); + testClasses.forEach(testClass -> { + DefaultGenerationContext generationContext = generator.createGenerationContext(testClass); + MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); + ClassName className = generator.processAheadOfTime(mergedConfig, generationContext); + assertThat(className).isNotNull(); + mappings.add(new Mapping(mergedConfig, className)); + generationContext.writeGeneratedContent(); + }); + return mappings; + } + + + private static MergedContextConfiguration buildMergedContextConfiguration(Class testClass) { + TestContextBootstrapper testContextBootstrapper = BootstrapUtils.resolveTestContextBootstrapper(testClass); + return testContextBootstrapper.buildMergedContextConfiguration(); + } + + record Mapping(MergedContextConfiguration mergedConfig, ClassName className) { + } + + private static final String[] expectedSourceFiles = { + // Global + "org/springframework/test/context/aot/AotTestContextInitializers__Generated.java", + "org/springframework/test/context/aot/AotTestAttributes__Generated.java", + // BasicSpringJupiterSharedConfigTests + "org/springframework/context/event/DefaultEventListenerFactory__TestContext001_BeanDefinitions.java", + "org/springframework/context/event/EventListenerMethodProcessor__TestContext001_BeanDefinitions.java", + "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterSharedConfigTests__TestContext001_ApplicationContextInitializer.java", + "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterSharedConfigTests__TestContext001_BeanFactoryRegistrations.java", + "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterSharedConfigTests__TestContext001_ManagementApplicationContextInitializer.java", + "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterSharedConfigTests__TestContext001_ManagementBeanFactoryRegistrations.java", + "org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext001_BeanDefinitions.java", + "org/springframework/test/context/aot/samples/management/ManagementConfiguration__TestContext001_BeanDefinitions.java", + "org/springframework/test/context/aot/samples/management/ManagementMessageService__TestContext001_ManagementBeanDefinitions.java", + // BasicSpringJupiterTests -- not generated b/c already generated for BasicSpringJupiterSharedConfigTests. + // BasicSpringJupiterTests.NestedTests + "org/springframework/context/event/DefaultEventListenerFactory__TestContext002_BeanDefinitions.java", + "org/springframework/context/event/EventListenerMethodProcessor__TestContext002_BeanDefinitions.java", + "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests_NestedTests__TestContext002_ApplicationContextInitializer.java", + "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests_NestedTests__TestContext002_BeanFactoryRegistrations.java", + "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests_NestedTests__TestContext002_ManagementApplicationContextInitializer.java", + "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests_NestedTests__TestContext002_ManagementBeanFactoryRegistrations.java", + "org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext002_BeanDefinitions.java", + "org/springframework/test/context/aot/samples/management/ManagementConfiguration__TestContext002_BeanDefinitions.java", + "org/springframework/test/context/aot/samples/management/ManagementMessageService__TestContext002_ManagementBeanDefinitions.java", + // BasicSpringTestNGTests + "org/springframework/context/event/DefaultEventListenerFactory__TestContext003_BeanDefinitions.java", + "org/springframework/context/event/EventListenerMethodProcessor__TestContext003_BeanDefinitions.java", + "org/springframework/test/context/aot/samples/basic/BasicSpringTestNGTests__TestContext003_ApplicationContextInitializer.java", + "org/springframework/test/context/aot/samples/basic/BasicSpringTestNGTests__TestContext003_BeanFactoryRegistrations.java", + "org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext003_BeanDefinitions.java", + // BasicSpringVintageTests + "org/springframework/context/event/DefaultEventListenerFactory__TestContext004_BeanDefinitions.java", + "org/springframework/context/event/EventListenerMethodProcessor__TestContext004_BeanDefinitions.java", + "org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests__TestContext004_ApplicationContextInitializer.java", + "org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests__TestContext004_BeanFactoryRegistrations.java", + "org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext004_BeanDefinitions.java", + // SqlScriptsSpringJupiterTests + "org/springframework/context/event/DefaultEventListenerFactory__TestContext005_BeanDefinitions.java", + "org/springframework/context/event/EventListenerMethodProcessor__TestContext005_BeanDefinitions.java", + "org/springframework/test/context/aot/samples/jdbc/SqlScriptsSpringJupiterTests__TestContext005_ApplicationContextInitializer.java", + "org/springframework/test/context/aot/samples/jdbc/SqlScriptsSpringJupiterTests__TestContext005_BeanFactoryRegistrations.java", + "org/springframework/test/context/jdbc/EmptyDatabaseConfig__TestContext005_BeanDefinitions.java", + // WebSpringJupiterTests + "org/springframework/context/event/DefaultEventListenerFactory__TestContext006_BeanDefinitions.java", + "org/springframework/context/event/EventListenerMethodProcessor__TestContext006_BeanDefinitions.java", + "org/springframework/test/context/aot/samples/web/WebSpringJupiterTests__TestContext006_ApplicationContextInitializer.java", + "org/springframework/test/context/aot/samples/web/WebSpringJupiterTests__TestContext006_BeanFactoryRegistrations.java", + "org/springframework/test/context/aot/samples/web/WebTestConfiguration__TestContext006_BeanDefinitions.java", + "org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration__TestContext006_Autowiring.java", + "org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration__TestContext006_BeanDefinitions.java", + "org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport__TestContext006_BeanDefinitions.java", + // XmlSpringJupiterTests + "org/springframework/context/event/DefaultEventListenerFactory__TestContext007_BeanDefinitions.java", + "org/springframework/context/event/EventListenerMethodProcessor__TestContext007_BeanDefinitions.java", + "org/springframework/test/context/aot/samples/common/DefaultMessageService__TestContext007_BeanDefinitions.java", + "org/springframework/test/context/aot/samples/xml/XmlSpringJupiterTests__TestContext007_ApplicationContextInitializer.java", + "org/springframework/test/context/aot/samples/xml/XmlSpringJupiterTests__TestContext007_BeanFactoryRegistrations.java" + }; + +} diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java index 26e9651f725..2e9dd795cf4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java @@ -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. @@ -16,429 +16,53 @@ package org.springframework.test.context.aot; -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.stream.Stream; - -import javax.sql.DataSource; - +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.aot.AotDetector; -import org.springframework.aot.generate.DefaultGenerationContext; -import org.springframework.aot.generate.GeneratedFiles.Kind; -import org.springframework.aot.generate.InMemoryGeneratedFiles; -import org.springframework.aot.hint.MemberCategory; -import org.springframework.aot.hint.RuntimeHints; -import org.springframework.aot.hint.TypeReference; -import org.springframework.aot.test.generate.CompilerFiles; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.test.tools.CompileWithForkedClassLoader; -import org.springframework.core.test.tools.TestCompiler; -import org.springframework.javapoet.ClassName; -import org.springframework.test.context.BootstrapUtils; -import org.springframework.test.context.MergedContextConfiguration; -import org.springframework.test.context.TestContextBootstrapper; -import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterSharedConfigTests; -import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests; -import org.springframework.test.context.aot.samples.basic.BasicSpringTestNGTests; -import org.springframework.test.context.aot.samples.basic.BasicSpringVintageTests; -import org.springframework.test.context.aot.samples.common.MessageService; -import org.springframework.test.context.aot.samples.jdbc.SqlScriptsSpringJupiterTests; -import org.springframework.test.context.aot.samples.web.WebSpringJupiterTests; -import org.springframework.test.context.aot.samples.web.WebSpringTestNGTests; -import org.springframework.test.context.aot.samples.web.WebSpringVintageTests; -import org.springframework.test.context.aot.samples.xml.XmlSpringJupiterTests; -import org.springframework.test.context.aot.samples.xml.XmlSpringTestNGTests; -import org.springframework.test.context.aot.samples.xml.XmlSpringVintageTests; -import org.springframework.test.context.env.YamlPropertySourceFactory; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.util.function.ThrowingConsumer; -import org.springframework.web.context.WebApplicationContext; +import org.springframework.core.SpringProperties; -import static java.util.Comparator.comparing; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.springframework.aot.hint.MemberCategory.INVOKE_DECLARED_CONSTRUCTORS; -import static org.springframework.aot.hint.MemberCategory.INVOKE_DECLARED_METHODS; -import static org.springframework.aot.hint.MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS; -import static org.springframework.aot.hint.MemberCategory.INVOKE_PUBLIC_METHODS; -import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.reflection; -import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.resource; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; +import static org.springframework.test.context.aot.TestContextAotGenerator.FAIL_ON_ERROR_PROPERTY_NAME; /** - * Tests for {@link TestContextAotGenerator}, {@link AotTestContextInitializers}, - * {@link AotTestAttributes}, {@link AotContextLoader}, and run-time hints. + * Tests for {@link TestContextAotGenerator}. * * @author Sam Brannen - * @since 6.0 + * @since 6.1 */ -@CompileWithForkedClassLoader -class TestContextAotGeneratorTests extends AbstractAotTests { - - /** - * End-to-end tests within the scope of the {@link TestContextAotGenerator}. - * - * @see AotIntegrationTests - */ - @Test - void endToEndTests() { - Set> testClasses = Set.of( - BasicSpringJupiterSharedConfigTests.class, - BasicSpringJupiterTests.class, - BasicSpringJupiterTests.NestedTests.class, - BasicSpringTestNGTests.class, - BasicSpringVintageTests.class, - SqlScriptsSpringJupiterTests.class, - XmlSpringJupiterTests.class, - WebSpringJupiterTests.class); - - InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles(); - TestContextAotGenerator generator = new TestContextAotGenerator(generatedFiles); - - generator.processAheadOfTime(testClasses.stream().sorted(comparing(Class::getName))); - - assertRuntimeHints(generator.getRuntimeHints()); - - List sourceFiles = generatedFiles.getGeneratedFiles(Kind.SOURCE).keySet().stream().toList(); - assertThat(sourceFiles).containsExactlyInAnyOrder(expectedSourceFiles); - - TestCompiler.forSystem().with(CompilerFiles.from(generatedFiles)).compile(ThrowingConsumer.of(compiled -> { - try { - System.setProperty(AotDetector.AOT_ENABLED, "true"); - AotTestAttributesFactory.reset(); - AotTestContextInitializersFactory.reset(); - - AotTestAttributes aotAttributes = AotTestAttributes.getInstance(); - assertThatExceptionOfType(UnsupportedOperationException.class) - .isThrownBy(() -> aotAttributes.setAttribute("foo", "bar")) - .withMessage("AOT attributes cannot be modified during AOT run-time execution"); - String key = "@SpringBootConfiguration-" + BasicSpringVintageTests.class.getName(); - assertThat(aotAttributes.getString(key)).isEqualTo("org.example.Main"); - assertThat(aotAttributes.getBoolean(key + "-active1")).isTrue(); - assertThat(aotAttributes.getBoolean(key + "-active2")).isTrue(); - assertThat(aotAttributes.getString("bogus")).isNull(); - assertThat(aotAttributes.getBoolean("bogus")).isFalse(); - - AotTestContextInitializers aotContextInitializers = new AotTestContextInitializers(); - for (Class testClass : testClasses) { - MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); - ApplicationContextInitializer contextInitializer = - aotContextInitializers.getContextInitializer(testClass); - assertThat(contextInitializer).isNotNull(); - ApplicationContext context = ((AotContextLoader) mergedConfig.getContextLoader()) - .loadContextForAotRuntime(mergedConfig, contextInitializer); - if (context instanceof WebApplicationContext wac) { - assertContextForWebTests(wac); - } - else if (testClass.getPackageName().contains("jdbc")) { - assertContextForJdbcTests(context); - } - else { - assertContextForBasicTests(context); - } - } - } - finally { - System.clearProperty(AotDetector.AOT_ENABLED); - AotTestAttributesFactory.reset(); - } - })); - } - - private static void assertRuntimeHints(RuntimeHints runtimeHints) { - assertReflectionRegistered(runtimeHints, AotTestContextInitializersCodeGenerator.GENERATED_MAPPINGS_CLASS_NAME, INVOKE_PUBLIC_METHODS); - assertReflectionRegistered(runtimeHints, AotTestAttributesCodeGenerator.GENERATED_ATTRIBUTES_CLASS_NAME, INVOKE_PUBLIC_METHODS); - - Stream.of( - "org.opentest4j.TestAbortedException", - "org.junit.AssumptionViolatedException", - "org.testng.SkipException" - ).forEach(type -> assertReflectionRegistered(runtimeHints, type)); - - Stream.of( - org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.class, - org.springframework.test.context.support.DefaultBootstrapContext.class - ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_PUBLIC_CONSTRUCTORS)); - - Stream.of( - org.springframework.test.context.support.DefaultTestContextBootstrapper.class, - org.springframework.test.context.support.DelegatingSmartContextLoader.class, - org.springframework.test.context.support.GenericGroovyXmlContextLoader.class, - org.springframework.test.context.web.GenericGroovyXmlWebContextLoader.class, - org.springframework.test.context.web.WebDelegatingSmartContextLoader.class, - org.springframework.test.context.web.WebTestContextBootstrapper.class - ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS)); - - Stream.of( - org.springframework.test.context.web.WebAppConfiguration.class - ).forEach(type -> assertAnnotationRegistered(runtimeHints, type)); - - // TestExecutionListener - Stream.of( - // @TestExecutionListeners - org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests.DummyTestExecutionListener.class, - org.springframework.test.context.event.ApplicationEventsTestExecutionListener.class, - org.springframework.test.context.event.EventPublishingTestExecutionListener.class, - org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener.class, - org.springframework.test.context.support.DependencyInjectionTestExecutionListener.class, - org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener.class, - org.springframework.test.context.support.DirtiesContextTestExecutionListener.class, - org.springframework.test.context.transaction.TransactionalTestExecutionListener.class, - org.springframework.test.context.web.ServletTestExecutionListener.class - ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS)); - - // ContextCustomizerFactory - Stream.of( - "org.springframework.test.context.support.DynamicPropertiesContextCustomizerFactory", - "org.springframework.test.context.web.socket.MockServerContainerContextCustomizerFactory", - "org.springframework.test.context.aot.samples.basic.ImportsContextCustomizerFactory" - ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS)); - - Stream.of( - // @BootstrapWith - org.springframework.test.context.aot.samples.basic.BasicSpringVintageTests.CustomXmlBootstrapper.class, - // @ContextConfiguration(initializers = ...) - org.springframework.test.context.aot.samples.basic.BasicSpringTestNGTests.CustomInitializer.class, - // @ContextConfiguration(loader = ...) - org.springframework.test.context.support.AnnotationConfigContextLoader.class, - // @ActiveProfiles(resolver = ...) - org.springframework.test.context.aot.samples.basic.SpanishActiveProfilesResolver.class - ).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS)); - - // @ContextConfiguration(locations = ...) - assertThat(resource().forResource("org/springframework/test/context/aot/samples/xml/test-config.xml")) - .accepts(runtimeHints); - - // @TestPropertySource(locations = ...) - assertThat(resource().forResource("org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.properties")) - .as("@TestPropertySource(locations)") - .accepts(runtimeHints); - - // @YamlTestProperties(...) - assertThat(resource().forResource("org/springframework/test/context/aot/samples/basic/test1.yaml")) - .as("@YamlTestProperties: test1.yaml") - .accepts(runtimeHints); - assertThat(resource().forResource("org/springframework/test/context/aot/samples/basic/test2.yaml")) - .as("@YamlTestProperties: test2.yaml") - .accepts(runtimeHints); - - // @TestPropertySource(factory = ...) - assertReflectionRegistered(runtimeHints, YamlPropertySourceFactory.class.getName(), INVOKE_DECLARED_CONSTRUCTORS); - - // @WebAppConfiguration(value = ...) - assertThat(resource().forResource("META-INF/web-resources/resources/Spring.js")).accepts(runtimeHints); - assertThat(resource().forResource("META-INF/web-resources/WEB-INF/views/home.jsp")).accepts(runtimeHints); - - // @Sql(scripts = ...) - assertThat(resource().forResource("org/springframework/test/context/jdbc/schema.sql")) - .accepts(runtimeHints); - assertThat(resource().forResource("org/springframework/test/context/aot/samples/jdbc/SqlScriptsSpringJupiterTests.test.sql")) - .accepts(runtimeHints); - } - - private static void assertReflectionRegistered(RuntimeHints runtimeHints, String type) { - assertThat(reflection().onType(TypeReference.of(type))) - .as("Reflection hint for %s", type) - .accepts(runtimeHints); - } +class TestContextAotGeneratorTests { - private static void assertReflectionRegistered(RuntimeHints runtimeHints, String type, MemberCategory memberCategory) { - assertThat(reflection().onType(TypeReference.of(type)).withMemberCategory(memberCategory)) - .as("Reflection hint for %s with category %s", type, memberCategory) - .accepts(runtimeHints); - } - - private static void assertReflectionRegistered(RuntimeHints runtimeHints, Class type, MemberCategory memberCategory) { - assertThat(reflection().onType(type).withMemberCategory(memberCategory)) - .as("Reflection hint for %s with category %s", type.getSimpleName(), memberCategory) - .accepts(runtimeHints); - } - - private static void assertAnnotationRegistered(RuntimeHints runtimeHints, Class annotationType) { - assertReflectionRegistered(runtimeHints, annotationType, INVOKE_DECLARED_METHODS); - } - - - @Test - void processAheadOfTimeWithBasicTests() { - // We cannot parameterize with the test classes, since @CompileWithTargetClassAccess - // cannot support @ParameterizedTest methods. - Set> testClasses = Set.of( - BasicSpringJupiterSharedConfigTests.class, - BasicSpringJupiterTests.class, - BasicSpringJupiterTests.NestedTests.class, - BasicSpringTestNGTests.class, - BasicSpringVintageTests.class); - - processAheadOfTime(testClasses, this::assertContextForBasicTests); - } - - private void assertContextForBasicTests(ApplicationContext context) { - assertThat(context.getEnvironment().getProperty("test.engine")).as("Environment").isNotNull(); - - MessageService messageService = context.getBean(MessageService.class); - ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context; - String expectedMessage = cac.getEnvironment().matchesProfiles("spanish") ? - "¡Hola, AOT!" : "Hello, AOT!"; - assertThat(messageService.generateMessage()).isEqualTo(expectedMessage); - } - - private void assertContextForJdbcTests(ApplicationContext context) throws Exception { - assertThat(context.getEnvironment().getProperty("test.engine")).as("Environment").isNotNull(); - assertThat(context.getBean(DataSource.class)).as("DataSource").isNotNull(); - } - - private void assertContextForWebTests(WebApplicationContext wac) throws Exception { - assertThat(wac.getEnvironment().getProperty("test.engine")).as("Environment").isNotNull(); - - MockMvc mockMvc = webAppContextSetup(wac).build(); - mockMvc.perform(get("/hello")).andExpectAll(status().isOk(), content().string("Hello, AOT!")); - } - - @Test - void processAheadOfTimeWithXmlTests() { - // We cannot parameterize with the test classes, since @CompileWithTargetClassAccess - // cannot support @ParameterizedTest methods. - Set> testClasses = Set.of( - XmlSpringJupiterTests.class, - XmlSpringTestNGTests.class, - XmlSpringVintageTests.class); - - processAheadOfTime(testClasses, context -> { - assertThat(context.getEnvironment().getProperty("test.engine")) - .as("Environment").isNotNull(); - - MessageService messageService = context.getBean(MessageService.class); - assertThat(messageService.generateMessage()).isEqualTo("Hello, AOT!"); - }); + @BeforeEach + @AfterEach + void resetFlag() { + SpringProperties.setProperty(FAIL_ON_ERROR_PROPERTY_NAME, null); } @Test - void processAheadOfTimeWithWebTests() { - // We cannot parameterize with the test classes, since @CompileWithTargetClassAccess - // cannot support @ParameterizedTest methods. - Set> testClasses = Set.of( - WebSpringJupiterTests.class, - WebSpringTestNGTests.class, - WebSpringVintageTests.class); - - processAheadOfTime(testClasses, context -> { - assertThat(context.getEnvironment().getProperty("test.engine")) - .as("Environment").isNotNull(); - - MockMvc mockMvc = webAppContextSetup((WebApplicationContext) context).build(); - mockMvc.perform(get("/hello")) - .andExpectAll(status().isOk(), content().string("Hello, AOT!")); - }); + void failOnErrorEnabledByDefault() { + assertThat(createGenerator().failOnError).isTrue(); } - - @SuppressWarnings("unchecked") - private void processAheadOfTime(Set> testClasses, ThrowingConsumer result) { - InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles(); - TestContextAotGenerator generator = new TestContextAotGenerator(generatedFiles); - List mappings = processAheadOfTime(generator, testClasses); - TestCompiler.forSystem().with(CompilerFiles.from(generatedFiles)).compile(ThrowingConsumer.of(compiled -> { - for (Mapping mapping : mappings) { - MergedContextConfiguration mergedConfig = mapping.mergedConfig(); - ApplicationContextInitializer contextInitializer = - compiled.getInstance(ApplicationContextInitializer.class, mapping.className().reflectionName()); - ApplicationContext context = ((AotContextLoader) mergedConfig.getContextLoader()) - .loadContextForAotRuntime(mergedConfig, contextInitializer); - result.accept(context); - } - })); + @ParameterizedTest + @ValueSource(strings = { "true", " True\t" }) + void failOnErrorEnabledViaSpringProperty(String value) { + SpringProperties.setProperty(FAIL_ON_ERROR_PROPERTY_NAME, value); + assertThat(createGenerator().failOnError).isTrue(); } - private List processAheadOfTime(TestContextAotGenerator generator, Set> testClasses) { - List mappings = new ArrayList<>(); - testClasses.forEach(testClass -> { - DefaultGenerationContext generationContext = generator.createGenerationContext(testClass); - MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); - ClassName className = generator.processAheadOfTime(mergedConfig, generationContext); - assertThat(className).isNotNull(); - mappings.add(new Mapping(mergedConfig, className)); - generationContext.writeGeneratedContent(); - }); - return mappings; + @ParameterizedTest + @ValueSource(strings = { "false", " False\t", "x" }) + void failOnErrorDisabledViaSpringProperty(String value) { + SpringProperties.setProperty(FAIL_ON_ERROR_PROPERTY_NAME, value); + assertThat(createGenerator().failOnError).isFalse(); } - private static MergedContextConfiguration buildMergedContextConfiguration(Class testClass) { - TestContextBootstrapper testContextBootstrapper = BootstrapUtils.resolveTestContextBootstrapper(testClass); - return testContextBootstrapper.buildMergedContextConfiguration(); + private static TestContextAotGenerator createGenerator() { + return new TestContextAotGenerator(null); } - record Mapping(MergedContextConfiguration mergedConfig, ClassName className) { - } - - private static final String[] expectedSourceFiles = { - // Global - "org/springframework/test/context/aot/AotTestContextInitializers__Generated.java", - "org/springframework/test/context/aot/AotTestAttributes__Generated.java", - // BasicSpringJupiterSharedConfigTests - "org/springframework/context/event/DefaultEventListenerFactory__TestContext001_BeanDefinitions.java", - "org/springframework/context/event/EventListenerMethodProcessor__TestContext001_BeanDefinitions.java", - "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterSharedConfigTests__TestContext001_ApplicationContextInitializer.java", - "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterSharedConfigTests__TestContext001_BeanFactoryRegistrations.java", - "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterSharedConfigTests__TestContext001_ManagementApplicationContextInitializer.java", - "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterSharedConfigTests__TestContext001_ManagementBeanFactoryRegistrations.java", - "org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext001_BeanDefinitions.java", - "org/springframework/test/context/aot/samples/management/ManagementConfiguration__TestContext001_BeanDefinitions.java", - "org/springframework/test/context/aot/samples/management/ManagementMessageService__TestContext001_ManagementBeanDefinitions.java", - // BasicSpringJupiterTests -- not generated b/c already generated for BasicSpringJupiterSharedConfigTests. - // BasicSpringJupiterTests.NestedTests - "org/springframework/context/event/DefaultEventListenerFactory__TestContext002_BeanDefinitions.java", - "org/springframework/context/event/EventListenerMethodProcessor__TestContext002_BeanDefinitions.java", - "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests_NestedTests__TestContext002_ApplicationContextInitializer.java", - "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests_NestedTests__TestContext002_BeanFactoryRegistrations.java", - "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests_NestedTests__TestContext002_ManagementApplicationContextInitializer.java", - "org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests_NestedTests__TestContext002_ManagementBeanFactoryRegistrations.java", - "org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext002_BeanDefinitions.java", - "org/springframework/test/context/aot/samples/management/ManagementConfiguration__TestContext002_BeanDefinitions.java", - "org/springframework/test/context/aot/samples/management/ManagementMessageService__TestContext002_ManagementBeanDefinitions.java", - // BasicSpringTestNGTests - "org/springframework/context/event/DefaultEventListenerFactory__TestContext003_BeanDefinitions.java", - "org/springframework/context/event/EventListenerMethodProcessor__TestContext003_BeanDefinitions.java", - "org/springframework/test/context/aot/samples/basic/BasicSpringTestNGTests__TestContext003_ApplicationContextInitializer.java", - "org/springframework/test/context/aot/samples/basic/BasicSpringTestNGTests__TestContext003_BeanFactoryRegistrations.java", - "org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext003_BeanDefinitions.java", - // BasicSpringVintageTests - "org/springframework/context/event/DefaultEventListenerFactory__TestContext004_BeanDefinitions.java", - "org/springframework/context/event/EventListenerMethodProcessor__TestContext004_BeanDefinitions.java", - "org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests__TestContext004_ApplicationContextInitializer.java", - "org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests__TestContext004_BeanFactoryRegistrations.java", - "org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext004_BeanDefinitions.java", - // SqlScriptsSpringJupiterTests - "org/springframework/context/event/DefaultEventListenerFactory__TestContext005_BeanDefinitions.java", - "org/springframework/context/event/EventListenerMethodProcessor__TestContext005_BeanDefinitions.java", - "org/springframework/test/context/aot/samples/jdbc/SqlScriptsSpringJupiterTests__TestContext005_ApplicationContextInitializer.java", - "org/springframework/test/context/aot/samples/jdbc/SqlScriptsSpringJupiterTests__TestContext005_BeanFactoryRegistrations.java", - "org/springframework/test/context/jdbc/EmptyDatabaseConfig__TestContext005_BeanDefinitions.java", - // WebSpringJupiterTests - "org/springframework/context/event/DefaultEventListenerFactory__TestContext006_BeanDefinitions.java", - "org/springframework/context/event/EventListenerMethodProcessor__TestContext006_BeanDefinitions.java", - "org/springframework/test/context/aot/samples/web/WebSpringJupiterTests__TestContext006_ApplicationContextInitializer.java", - "org/springframework/test/context/aot/samples/web/WebSpringJupiterTests__TestContext006_BeanFactoryRegistrations.java", - "org/springframework/test/context/aot/samples/web/WebTestConfiguration__TestContext006_BeanDefinitions.java", - "org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration__TestContext006_Autowiring.java", - "org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration__TestContext006_BeanDefinitions.java", - "org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport__TestContext006_BeanDefinitions.java", - // XmlSpringJupiterTests - "org/springframework/context/event/DefaultEventListenerFactory__TestContext007_BeanDefinitions.java", - "org/springframework/context/event/EventListenerMethodProcessor__TestContext007_BeanDefinitions.java", - "org/springframework/test/context/aot/samples/common/DefaultMessageService__TestContext007_BeanDefinitions.java", - "org/springframework/test/context/aot/samples/xml/XmlSpringJupiterTests__TestContext007_ApplicationContextInitializer.java", - "org/springframework/test/context/aot/samples/xml/XmlSpringJupiterTests__TestContext007_BeanFactoryRegistrations.java" - }; - } diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorUnitTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorUnitTests.java deleted file mode 100644 index c837242617c..00000000000 --- a/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorUnitTests.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.test.context.aot; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -import org.springframework.core.SpringProperties; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.context.aot.TestContextAotGenerator.FAIL_ON_ERROR_PROPERTY_NAME; - -/** - * Unit tests for {@link TestContextAotGenerator}. - * - * @author Sam Brannen - * @since 6.1 - */ -class TestContextAotGeneratorUnitTests { - - @BeforeEach - @AfterEach - void resetFlag() { - SpringProperties.setProperty(FAIL_ON_ERROR_PROPERTY_NAME, null); - } - - @Test - void failOnErrorEnabledByDefault() { - assertThat(createGenerator().failOnError).isTrue(); - } - - @ParameterizedTest - @ValueSource(strings = {"true", " True\t"}) - void failOnErrorEnabledViaSpringProperty(String value) { - SpringProperties.setProperty(FAIL_ON_ERROR_PROPERTY_NAME, value); - assertThat(createGenerator().failOnError).isTrue(); - } - - @ParameterizedTest - @ValueSource(strings = {"false", " False\t", "x"}) - void failOnErrorDisabledViaSpringProperty(String value) { - SpringProperties.setProperty(FAIL_ON_ERROR_PROPERTY_NAME, value); - assertThat(createGenerator().failOnError).isFalse(); - } - - - private static TestContextAotGenerator createGenerator() { - return new TestContextAotGenerator(null); - } - -}