HHH-11134 StringIndexOutOfBoundsException in BooleanTypeDescriptor fix
This commit is contained in:
parent
a21706bf02
commit
dd9c68a862
|
@ -95,11 +95,18 @@ public class BooleanTypeDescriptor extends AbstractTypeDescriptor<Boolean> {
|
|||
return isTrue( (Character) value ) ? TRUE : FALSE;
|
||||
}
|
||||
if ( String.class.isInstance( value ) ) {
|
||||
return isTrue( ( (String) value ).charAt( 0 ) ) ? TRUE : FALSE;
|
||||
return isTrue((String) value) ? TRUE : FALSE;
|
||||
}
|
||||
throw unknownWrap( value.getClass() );
|
||||
}
|
||||
|
||||
private boolean isTrue(String strValue) {
|
||||
if (strValue != null && !strValue.isEmpty()) {
|
||||
return isTrue(strValue.charAt(0));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isTrue(char charValue) {
|
||||
return charValue == characterValueTrue || charValue == characterValueTrueLC;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package org.hibernate.type.descriptor.java;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class BooleanTypeDescriptorTest {
|
||||
private BooleanTypeDescriptor underTest = new BooleanTypeDescriptor();
|
||||
|
||||
@Test
|
||||
public void testWrapShouldReturnTrueWhenYStringGiven() {
|
||||
// given
|
||||
// when
|
||||
Boolean result = underTest.wrap("Y", null);
|
||||
// then
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapShouldReturnFalseWhenFStringGiven() {
|
||||
// given
|
||||
// when
|
||||
Boolean result = underTest.wrap("N", null);
|
||||
// then
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapShouldReturnFalseWhenRandomStringGiven() {
|
||||
// given
|
||||
// when
|
||||
Boolean result = underTest.wrap("k", null);
|
||||
// then
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapShouldReturnNullWhenNullStringGiven() {
|
||||
// given
|
||||
// when
|
||||
Boolean result = underTest.wrap(null, null);
|
||||
// then
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapShouldReturnFalseWhenEmptyStringGiven() {
|
||||
// given
|
||||
// when
|
||||
Boolean result = underTest.wrap("", null);
|
||||
// then
|
||||
assertFalse(result);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue