Fix default charset testing for JDK21
This commit is contained in:
parent
4d46294088
commit
6685f2c89e
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue