-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-18073
BasicCollectionJavaType::wrap
should retain order of `Set…
…` to keep consistent with `deepCopy`
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../java/org/hibernate/orm/test/mapping/type/java/BasicCollectionJavaTypeDescriptorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.orm.test.mapping.type.java; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import org.hibernate.collection.internal.StandardSetSemantics; | ||
import org.hibernate.testing.orm.junit.JiraKey; | ||
import org.hibernate.type.descriptor.java.StringJavaType; | ||
import org.hibernate.type.descriptor.java.spi.BasicCollectionJavaType; | ||
import org.junit.Test; | ||
|
||
import java.lang.reflect.ParameterizedType; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
public class BasicCollectionJavaTypeDescriptorTest { | ||
|
||
private static final BasicCollectionJavaType<Set<String>, String> stringSetJavaType = createJavaType(); | ||
|
||
@Test | ||
@JiraKey( "HHH-18073" ) | ||
public void wrapShouldRetainOrderOfSet() { | ||
assertTrue("BasicCollectionJavaType.wrap() should retain order of Set", | ||
stringSetJavaType.wrap(Set.of( "foo", "bar" ), null) instanceof LinkedHashSet); | ||
} | ||
|
||
@Test | ||
public void deepCopyShouldRetainOrderOfSet() { | ||
assertTrue("BasicCollectionJavaType.getMutabilityPlan().deepCopy() should retain order of Set", | ||
stringSetJavaType.getMutabilityPlan().deepCopy(Set.of( "foo", "bar" )) instanceof LinkedHashSet); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private static BasicCollectionJavaType<Set<String>, String> createJavaType() { | ||
ParameterizedType type; | ||
try { | ||
type = (ParameterizedType) TestEntity.class.getDeclaredField("tags").getGenericType(); | ||
} catch (NoSuchFieldException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return new BasicCollectionJavaType<>( | ||
type, | ||
StringJavaType.INSTANCE, | ||
(StandardSetSemantics<String>) StandardSetSemantics.INSTANCE | ||
); | ||
} | ||
|
||
@Entity | ||
static class TestEntity { | ||
|
||
@Id | ||
@GeneratedValue | ||
Long id; | ||
|
||
Set<String> tags; | ||
} | ||
} |