From 6685f2c89e9248bd8ac3edfe8d2e8a95ee08d6e3 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Mon, 6 Mar 2023 14:00:26 +0100 Subject: [PATCH] Fix default charset testing for JDK21 --- .../binding/naming/NamingHelperTest.java | 43 ++----------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/naming/NamingHelperTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/naming/NamingHelperTest.java index ed541a8d88..5e70a9a58b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/naming/NamingHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/naming/NamingHelperTest.java @@ -6,26 +6,17 @@ */ package org.hibernate.orm.test.bootstrap.binding.naming; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.naming.NamingHelper; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.testing.util.ReflectionUtil; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExternalResource; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; public class NamingHelperTest extends BaseUnitTestCase { - @Rule - public DefaultCharset defaultCharset = new DefaultCharset(); - @Test @TestForIssue(jiraKey = "HHH-12357") public void generateHashedFkName() { @@ -33,15 +24,11 @@ public class NamingHelperTest extends BaseUnitTestCase { Identifier authorsDe = new Identifier( "Autoren", false ); Identifier authorId = new Identifier( "autor_id", false ); - defaultCharset.set( StandardCharsets.ISO_8859_1 ); - - String fkNameLatin1 = NamingHelper.INSTANCE.generateHashedFkName( "FK", booksDe, authorsDe, authorId ); + String fkNameLatin1 = NamingHelper.withCharset( "ISO-8859-1" ).generateHashedFkName( "FK", booksDe, authorsDe, authorId ); assertEquals( "FKpvm24wh1qwbmx6xjcbc7uv5f7", fkNameLatin1 ); - defaultCharset.set( StandardCharsets.UTF_8 ); - - String fkNameUtf8 = NamingHelper.INSTANCE.generateHashedFkName( "FK", booksDe, authorsDe, authorId ); + String fkNameUtf8 = NamingHelper.withCharset( "UTF8" ).generateHashedFkName( "FK", booksDe, authorsDe, authorId ); assertEquals( "FKdgopp1hqnm8c1o6sfbb3tbeh", fkNameUtf8 ); } @@ -53,37 +40,13 @@ public class NamingHelperTest extends BaseUnitTestCase { Identifier authorsDe = new Identifier( "Autoren", false ); Identifier authorId = new Identifier( "autor_id", false ); - defaultCharset.set( StandardCharsets.ISO_8859_1 ); - String fkNameLatin1 = NamingHelper.withCharset( "UTF8" ).generateHashedFkName( "FK", booksDe, authorsDe, authorId ); assertEquals( "FKdgopp1hqnm8c1o6sfbb3tbeh", fkNameLatin1 ); - defaultCharset.set( StandardCharsets.UTF_8 ); - String fkNameUtf8 = NamingHelper.withCharset( "UTF8" ).generateHashedFkName( "FK", booksDe, authorsDe, authorId ); assertEquals( "FKdgopp1hqnm8c1o6sfbb3tbeh", fkNameUtf8 ); } - public static class DefaultCharset extends ExternalResource { - - private Charset prev; - - @Override - protected void before() { - prev = ReflectionUtil.getStaticFieldValue( Charset.class, "defaultCharset" ); - } - - @Override - protected void after() { - set( prev ); - } - - public void set(Charset charset) { - ReflectionUtil.setStaticField( Charset.class, "defaultCharset", charset ); - } - - } - }