Make list semantics setting explicit for failing tests

This commit is contained in:
Christian Beikov 2022-02-02 19:34:37 +01:00
parent 7aaeebe3af
commit a91d23825f
5 changed files with 47 additions and 10 deletions

View File

@ -15,6 +15,7 @@ import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope; 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.ServiceRegistry;
import org.hibernate.testing.orm.junit.SettingProvider; import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -35,7 +36,7 @@ import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
@ServiceRegistry( @ServiceRegistry(
settingProviders = @SettingProvider( settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS, settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsListSemanticsTests.ImplicitListAsListProvider.class ) provider = ImplicitListAsListProvider.class )
) )
@DomainModel( annotatedClasses = ImplicitListAsListSemanticsTests.AnEntity.class ) @DomainModel( annotatedClasses = ImplicitListAsListSemanticsTests.AnEntity.class )
public class ImplicitListAsListSemanticsTests { public class ImplicitListAsListSemanticsTests {
@ -100,11 +101,4 @@ public class ImplicitListAsListSemanticsTests {
this.name = name; this.name = name;
} }
} }
public static class ImplicitListAsListProvider implements SettingProvider.Provider<CollectionClassification> {
@Override
public CollectionClassification getSetting() {
return CollectionClassification.LIST;
}
}
} }

View File

@ -10,11 +10,17 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.mapping.Bag; import org.hibernate.mapping.Bag;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope; 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 org.junit.jupiter.api.Test;
import jakarta.persistence.Basic; import jakarta.persistence.Basic;
@ -25,6 +31,7 @@ import jakarta.persistence.OrderColumn;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import static org.assertj.core.api.Assertions.assertThat; 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 * 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 * @author Steve Ebersole
*/ */
@ServiceRegistry(
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsListProvider.class
)
)
@DomainModel( annotatedClasses = ImplicitListDefaultSemanticsTests.AnEntity.class ) @DomainModel( annotatedClasses = ImplicitListDefaultSemanticsTests.AnEntity.class )
public class ImplicitListDefaultSemanticsTests { public class ImplicitListDefaultSemanticsTests {
@Test @Test

View File

@ -14,17 +14,27 @@ import org.hibernate.type.CustomCollectionType;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope; 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.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope; 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.AfterEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; 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; import static org.junit.jupiter.api.Assertions.fail;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ServiceRegistry(
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsListProvider.class
)
)
@DomainModel( annotatedClasses = { TheEntityWithUniqueList.class, TheEntityWithUniqueListRegistration.class } ) @DomainModel( annotatedClasses = { TheEntityWithUniqueList.class, TheEntityWithUniqueListRegistration.class } )
@SessionFactory @SessionFactory
public class CustomSemanticsTest { public class CustomSemanticsTest {

View File

@ -7,6 +7,7 @@
package org.hibernate.orm.test.mapping.onetomany; package org.hibernate.orm.test.mapping.onetomany;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@ -616,8 +617,8 @@ public class OneToManyBidirectionalTest {
assertThat( statistics.getPrepareStatementCount(), is( 1L ) ); assertThat( statistics.getPrepareStatementCount(), is( 1L ) );
assertTrue( Hibernate.isInitialized( order.getLineItems() ) ); assertTrue( Hibernate.isInitialized( order.getLineItems() ) );
// With BAG semantics, the list will contain duplicates, so filter that
assertThat( order.getLineItems().size(), is( 2 ) ); assertThat( new HashSet<>( order.getLineItems()).size(), is( 2 ) );
} ); } );
} }

View File

@ -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<CollectionClassification> {
@Override
public CollectionClassification getSetting() {
return CollectionClassification.LIST;
}
}