#817 - SqlRow getBoolean() does not treat numeric 1 value as true (with MySql and other DB's without native boolean type)

This commit is contained in:
Robin Bygrave
2016-08-29 20:54:49 +12:00
parent d1e2176a5a
commit 59670d0303
3 changed files with 56 additions and 0 deletions
@@ -0,0 +1,19 @@
package com.avaje.ebean;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class SqlRowBooleanTest {
@Test
public void getBoolean() {
SqlQuery sqlQuery = Ebean.createSqlQuery("SELECT 1 IS NOT NULL AS `ISNT_NULL`");
SqlRow row = sqlQuery.findUnique();
Boolean value = row.getBoolean("ISNT_NULL");
assertThat(value).isTrue();
}
}
@@ -0,0 +1,34 @@
package com.avaje.ebeaninternal.server.core;
import org.junit.Test;
import static org.junit.Assert.*;
public class BasicTypeConverterTest {
@Test
public void toBoolean_when_1_long() throws Exception {
assertTrue(BasicTypeConverter.toBoolean(1L, "T"));
}
@Test
public void toBoolean_when_1_int() throws Exception {
assertTrue(BasicTypeConverter.toBoolean(1, "T"));
}
@Test
public void toBoolean_when_0() throws Exception {
assertFalse(BasicTypeConverter.toBoolean(0L, "T"));
}
@Test
public void toBoolean_when_TrueValue() throws Exception {
assertTrue(BasicTypeConverter.toBoolean("T", "T"));
}
@Test
public void toBoolean_when_notTrueValue() throws Exception {
assertFalse(BasicTypeConverter.toBoolean("F", "T"));
}
}