diff --git a/src/main/java/com/avaje/ebean/config/PropertiesWrapper.java b/src/main/java/com/avaje/ebean/config/PropertiesWrapper.java index 66bcf9ac0..4bda1c763 100644 --- a/src/main/java/com/avaje/ebean/config/PropertiesWrapper.java +++ b/src/main/java/com/avaje/ebean/config/PropertiesWrapper.java @@ -141,8 +141,8 @@ public class PropertiesWrapper { * Return a Enum property value. */ public > T getEnum(Class enumType, String key, T defaultValue) { - String level = get(key, defaultValue.name()); - return Enum.valueOf(enumType, level.toUpperCase()); + String level = get(key, null); + return (level == null) ? defaultValue : Enum.valueOf(enumType, level.toUpperCase()); } } diff --git a/src/test/java/com/avaje/ebean/config/PropertiesWrapperTest.java b/src/test/java/com/avaje/ebean/config/PropertiesWrapperTest.java index 24422d657..43f8606c9 100644 --- a/src/test/java/com/avaje/ebean/config/PropertiesWrapperTest.java +++ b/src/test/java/com/avaje/ebean/config/PropertiesWrapperTest.java @@ -1,5 +1,6 @@ package com.avaje.ebean.config; +import com.avaje.ebean.config.dbplatform.DbPlatformName; import org.junit.Test; import java.util.Properties; @@ -17,6 +18,18 @@ public class PropertiesWrapperTest { assertEquals("myserver", pw.getServerName()); } + @Test + public void testGetEnum() { + + Properties properties = new Properties(); + properties.put("platform","postgres"); + + PropertiesWrapper pw = new PropertiesWrapper("pref", "myserver", properties); + assertEquals(DbPlatformName.POSTGRES, pw.getEnum(DbPlatformName.class, "platform", DbPlatformName.H2)); + assertEquals(DbPlatformName.H2, pw.getEnum(DbPlatformName.class, "junk", DbPlatformName.H2)); + assertNull(pw.getEnum(DbPlatformName.class, "junk", null)); + } + @Test public void testTrimPropertyValues() {