From a91d23825fee54ee64edf140709781833b392825 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 2 Feb 2022 19:34:37 +0100 Subject: [PATCH] Make list semantics setting explicit for failing tests --- .../ImplicitListAsListSemanticsTests.java | 10 ++-------- .../ImplicitListDefaultSemanticsTests.java | 13 +++++++++++++ .../semantics/CustomSemanticsTest.java | 10 ++++++++++ .../onetomany/OneToManyBidirectionalTest.java | 5 +++-- .../orm/junit/ImplicitListAsListProvider.java | 19 +++++++++++++++++++ 5 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/ImplicitListAsListProvider.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/ImplicitListAsListSemanticsTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/ImplicitListAsListSemanticsTests.java index 6153d84eb1..8efe1345fc 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/ImplicitListAsListSemanticsTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/ImplicitListAsListSemanticsTests.java @@ -15,6 +15,7 @@ import org.hibernate.metamodel.CollectionClassification; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModelScope; +import org.hibernate.testing.orm.junit.ImplicitListAsListProvider; import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SettingProvider; import org.junit.jupiter.api.Test; @@ -35,7 +36,7 @@ import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS; @ServiceRegistry( settingProviders = @SettingProvider( settingName = DEFAULT_LIST_SEMANTICS, - provider = ImplicitListAsListSemanticsTests.ImplicitListAsListProvider.class ) + provider = ImplicitListAsListProvider.class ) ) @DomainModel( annotatedClasses = ImplicitListAsListSemanticsTests.AnEntity.class ) public class ImplicitListAsListSemanticsTests { @@ -100,11 +101,4 @@ public class ImplicitListAsListSemanticsTests { this.name = name; } } - - public static class ImplicitListAsListProvider implements SettingProvider.Provider { - @Override - public CollectionClassification getSetting() { - return CollectionClassification.LIST; - } - } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/ImplicitListDefaultSemanticsTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/ImplicitListDefaultSemanticsTests.java index e521f511b1..41115dae45 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/ImplicitListDefaultSemanticsTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/ImplicitListDefaultSemanticsTests.java @@ -10,11 +10,17 @@ import java.util.Collection; import java.util.List; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Environment; import org.hibernate.mapping.Bag; import org.hibernate.mapping.Property; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModelScope; +import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider; +import org.hibernate.testing.orm.junit.ImplicitListAsListProvider; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.Setting; +import org.hibernate.testing.orm.junit.SettingProvider; import org.junit.jupiter.api.Test; import jakarta.persistence.Basic; @@ -25,6 +31,7 @@ import jakarta.persistence.OrderColumn; import jakarta.persistence.Table; import static org.assertj.core.api.Assertions.assertThat; +import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS; /** * Uses the default {@value AvailableSettings#DEFAULT_LIST_SEMANTICS} value of LIST @@ -32,6 +39,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Steve Ebersole */ +@ServiceRegistry( + settingProviders = @SettingProvider( + settingName = DEFAULT_LIST_SEMANTICS, + provider = ImplicitListAsListProvider.class + ) +) @DomainModel( annotatedClasses = ImplicitListDefaultSemanticsTests.AnEntity.class ) public class ImplicitListDefaultSemanticsTests { @Test diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/semantics/CustomSemanticsTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/semantics/CustomSemanticsTest.java index 9c87a2e546..8a93f114e4 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/semantics/CustomSemanticsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/semantics/CustomSemanticsTest.java @@ -14,17 +14,27 @@ import org.hibernate.type.CustomCollectionType; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModelScope; +import org.hibernate.testing.orm.junit.ImplicitListAsListProvider; +import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.SettingProvider; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS; import static org.junit.jupiter.api.Assertions.fail; /** * @author Steve Ebersole */ +@ServiceRegistry( + settingProviders = @SettingProvider( + settingName = DEFAULT_LIST_SEMANTICS, + provider = ImplicitListAsListProvider.class + ) +) @DomainModel( annotatedClasses = { TheEntityWithUniqueList.class, TheEntityWithUniqueListRegistration.class } ) @SessionFactory public class CustomSemanticsTest { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/onetomany/OneToManyBidirectionalTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/onetomany/OneToManyBidirectionalTest.java index 85db98e2b1..1180d91546 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/onetomany/OneToManyBidirectionalTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/onetomany/OneToManyBidirectionalTest.java @@ -7,6 +7,7 @@ package org.hibernate.orm.test.mapping.onetomany; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import jakarta.persistence.Entity; import jakarta.persistence.Id; @@ -616,8 +617,8 @@ public class OneToManyBidirectionalTest { assertThat( statistics.getPrepareStatementCount(), is( 1L ) ); assertTrue( Hibernate.isInitialized( order.getLineItems() ) ); - - assertThat( order.getLineItems().size(), is( 2 ) ); + // With BAG semantics, the list will contain duplicates, so filter that + assertThat( new HashSet<>( order.getLineItems()).size(), is( 2 ) ); } ); } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/ImplicitListAsListProvider.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/ImplicitListAsListProvider.java new file mode 100644 index 0000000000..985cb333e9 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/ImplicitListAsListProvider.java @@ -0,0 +1,19 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.testing.orm.junit; + +import org.hibernate.metamodel.CollectionClassification; + +/** + * @author Christian Beikov + */ +public class ImplicitListAsListProvider implements SettingProvider.Provider { + @Override + public CollectionClassification getSetting() { + return CollectionClassification.LIST; + } +}