Skip to content

Commit

Permalink
Handle short in PropertyElf (brettwooldridge#1581)
Browse files Browse the repository at this point in the history
  • Loading branch information
freafrea authored Jan 11, 2021
1 parent a228b6d commit 29eb681
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/zaxxer/hikari/util/PropertyElf.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 29eb681

Please sign in to comment.