Skip to content
Snippets Groups Projects
Commit f01e2b85 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Switch to options

parent ec9b05f6
No related branches found
No related tags found
No related merge requests found
......@@ -58,10 +58,10 @@ object ConfigUtils extends Logging {
* @param path Nested path to get from map
* @return Nested map
*/
def getMapFromPath(map: Map[String, Any], path: List[String]): Map[String, Any] = {
val value = getValueFromPath(map, path) getOrElse { return null }
def getMapFromPath(map: Map[String, Any], path: List[String]): Option[Map[String, Any]] = {
val value = getValueFromPath(map, path) getOrElse { return None }
value match {
case m: Map[_, _] => m.asInstanceOf[Map[String, Any]]
case m: Map[_, _] => Some(m.asInstanceOf[Map[String, Any]])
case _ => throw new IllegalStateException("Value is not a map: " + value)
}
}
......
......@@ -26,8 +26,8 @@ class ConfigUtilsTest extends TestNGSuite with MockitoSugar with Matchers {
}
@Test def testGetMapFromPath: Unit = {
getMapFromPath(map1, List("dummy")) shouldBe Map("dummy" -> 1)
getMapFromPath(map1, List("nested3", "nested2", "nested1")) shouldBe Map("dummy" -> 1)
getMapFromPath(map1, List("dummy")) shouldBe Some(Map("dummy" -> 1))
getMapFromPath(map1, List("nested3", "nested2", "nested1")) shouldBe Some(Map("dummy" -> 1))
intercept[IllegalStateException] {
getMapFromPath(map1, List("dummy", "dummy"))
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment