Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle short in PropertyElf #1581

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/com/zaxxer/hikari/util/PropertyElf.java
Expand Up @@ -143,6 +143,9 @@ private static void setProperty(final Object target, final String propName, fina
else if (paramClass == long.class) {
writeMethod.invoke(target, Long.parseLong(propValue.toString()));
}
else if (paramClass == short.class) {
writeMethod.invoke(target, Short.parseShort(propValue.toString()));
}
else if (paramClass == boolean.class || paramClass == Boolean.class) {
writeMethod.invoke(target, Boolean.parseBoolean(propValue.toString()));
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/zaxxer/hikari/mocks/TestObject.java
Expand Up @@ -4,6 +4,7 @@ public class TestObject
{
private TestObject testObject;
private String string;
private short shortRaw;

public void setTestObject(TestObject testObject)
{
Expand All @@ -24,4 +25,12 @@ public String getString()
{
return string;
}

public short getShortRaw() {
return shortRaw;
}

public void setShortRaw(short shortRaw) {
this.shortRaw = shortRaw;
}
}
2 changes: 2 additions & 0 deletions src/test/java/com/zaxxer/hikari/util/PropertyElfTest.java
Expand Up @@ -18,9 +18,11 @@ public void setTargetFromProperties() throws Exception
Properties properties = new Properties();
properties.setProperty("string", "aString");
properties.setProperty("testObject", "com.zaxxer.hikari.mocks.TestObject");
properties.setProperty("shortRaw", "1");
TestObject testObject = new TestObject();
PropertyElf.setTargetFromProperties(testObject, properties);
assertEquals("aString", testObject.getString());
assertEquals((short) 1, testObject.getShortRaw());
assertEquals(com.zaxxer.hikari.mocks.TestObject.class, testObject.getTestObject().getClass());
assertNotSame(testObject, testObject.getTestObject());
}
Expand Down