-
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.
Fix String index out of range when wrapping an char
- Loading branch information
Showing
2 changed files
with
91 additions
and
1 deletion.
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
87 changes: 87 additions & 0 deletions
87
hibernate-core/src/test/java/org/hibernate/orm/test/type/CharacterTypeTest.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,87 @@ | ||
/* | ||
* 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.type; | ||
|
||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
@DomainModel( | ||
annotatedClasses = CharacterTypeTest.TestEntity.class | ||
) | ||
@SessionFactory | ||
public class CharacterTypeTest { | ||
|
||
@BeforeEach | ||
public void setUp(SessionFactoryScope scope) { | ||
scope.inTransaction( | ||
session -> { | ||
TestEntity dataTypes = new TestEntity( 1, ' ' ); | ||
session.persist( dataTypes ); | ||
} | ||
); | ||
} | ||
|
||
@Test | ||
public void transientTest(SessionFactoryScope scope) { | ||
scope.inTransaction( | ||
session -> { | ||
TestEntity d1 = session.find( TestEntity.class, 1 ); | ||
assertNotNull( d1 ); | ||
assertEquals( ' ', d1.getCharacterData() ); | ||
d1.setCharacterData( null ); | ||
} | ||
); | ||
|
||
scope.inTransaction( | ||
session -> { | ||
TestEntity d1 = session.find( TestEntity.class, 1 ); | ||
assertNotNull( d1 ); | ||
assertNull( d1.getCharacterData() ); | ||
} | ||
); | ||
} | ||
|
||
@Entity(name = "TestEntity") | ||
public static class TestEntity { | ||
|
||
@Id | ||
private Integer id; | ||
|
||
private Character characterData; | ||
|
||
public TestEntity() { | ||
} | ||
|
||
public TestEntity(Integer id, Character characterData) { | ||
this.id = id; | ||
this.characterData = characterData; | ||
} | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setCharacterData(Character characterData) { | ||
this.characterData = characterData; | ||
} | ||
|
||
public Character getCharacterData() { | ||
return characterData; | ||
} | ||
} | ||
|
||
} |