Handle short in PropertyElf (#1581)

pull/1716/head
freafrea 4 years ago committed by GitHub
parent a228b6df93
commit 29eb681cbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -143,6 +143,9 @@ public final class PropertyElf
else if (paramClass == long.class) { else if (paramClass == long.class) {
writeMethod.invoke(target, Long.parseLong(propValue.toString())); 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) { else if (paramClass == boolean.class || paramClass == Boolean.class) {
writeMethod.invoke(target, Boolean.parseBoolean(propValue.toString())); writeMethod.invoke(target, Boolean.parseBoolean(propValue.toString()));
} }

@ -4,6 +4,7 @@ public class TestObject
{ {
private TestObject testObject; private TestObject testObject;
private String string; private String string;
private short shortRaw;
public void setTestObject(TestObject testObject) public void setTestObject(TestObject testObject)
{ {
@ -24,4 +25,12 @@ public class TestObject
{ {
return string; return string;
} }
public short getShortRaw() {
return shortRaw;
}
public void setShortRaw(short shortRaw) {
this.shortRaw = shortRaw;
}
} }

@ -18,9 +18,11 @@ public class PropertyElfTest
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("string", "aString"); properties.setProperty("string", "aString");
properties.setProperty("testObject", "com.zaxxer.hikari.mocks.TestObject"); properties.setProperty("testObject", "com.zaxxer.hikari.mocks.TestObject");
properties.setProperty("shortRaw", "1");
TestObject testObject = new TestObject(); TestObject testObject = new TestObject();
PropertyElf.setTargetFromProperties(testObject, properties); PropertyElf.setTargetFromProperties(testObject, properties);
assertEquals("aString", testObject.getString()); assertEquals("aString", testObject.getString());
assertEquals((short) 1, testObject.getShortRaw());
assertEquals(com.zaxxer.hikari.mocks.TestObject.class, testObject.getTestObject().getClass()); assertEquals(com.zaxxer.hikari.mocks.TestObject.class, testObject.getTestObject().getClass());
assertNotSame(testObject, testObject.getTestObject()); assertNotSame(testObject, testObject.getTestObject());
} }

Loading…
Cancel
Save