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

No null returns at files and strings

parent bfdd3e42
No related branches found
No related tags found
No related merge requests found
...@@ -337,7 +337,8 @@ object ConfigUtils extends Logging { ...@@ -337,7 +337,8 @@ object ConfigUtils extends Logging {
*/ */
implicit def configValue2file(value: ConfigValue): File = { implicit def configValue2file(value: ConfigValue): File = {
//TODO: throw IllegalStateException //TODO: throw IllegalStateException
if (value != null && value.value != null && value.value != None) new File(any2string(value.value)) else null if (value != null && value.value != null && value.value != None) new File(any2string(value.value))
else throw new IllegalStateException("Value does not exist")
} }
/** /**
...@@ -346,7 +347,8 @@ object ConfigUtils extends Logging { ...@@ -346,7 +347,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionFile(value: ConfigValue): Option[File] = { implicit def configValue2optionFile(value: ConfigValue): Option[File] = {
if (value != null && value.value != null && value.value != None) Some(new File(any2string(value.value))) else None if (value != null && value.value != null && value.value != None) Some(new File(any2string(value.value)))
else None
} }
/** /**
...@@ -356,7 +358,8 @@ object ConfigUtils extends Logging { ...@@ -356,7 +358,8 @@ object ConfigUtils extends Logging {
*/ */
implicit def configValue2string(value: ConfigValue): String = { implicit def configValue2string(value: ConfigValue): String = {
//TODO: throw IllegalStateException //TODO: throw IllegalStateException
if (value != null && value.value != null && value.value != None) any2string(value.value) else null if (value != null && value.value != null && value.value != None) any2string(value.value)
else throw new IllegalStateException("Value does not exist")
} }
/** /**
...@@ -365,7 +368,8 @@ object ConfigUtils extends Logging { ...@@ -365,7 +368,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionString(value: ConfigValue): Option[String] = { implicit def configValue2optionString(value: ConfigValue): Option[String] = {
if (value != null && value.value != null && value.value != None) Some(any2string(value.value)) else None if (value != null && value.value != null && value.value != None) Some(any2string(value.value))
else None
} }
/** /**
...@@ -384,7 +388,8 @@ object ConfigUtils extends Logging { ...@@ -384,7 +388,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionLong(value: ConfigValue): Option[Long] = { implicit def configValue2optionLong(value: ConfigValue): Option[Long] = {
if (value != null && value.value != null && value.value != None) Option(any2long(value.value)) else None if (value != null && value.value != null && value.value != None) Option(any2long(value.value))
else None
} }
/** /**
...@@ -403,7 +408,8 @@ object ConfigUtils extends Logging { ...@@ -403,7 +408,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionInt(value: ConfigValue): Option[Int] = { implicit def configValue2optionInt(value: ConfigValue): Option[Int] = {
if (value != null && value.value != null && value.value != None) Option(any2int(value.value)) else None if (value != null && value.value != null && value.value != None) Option(any2int(value.value))
else None
} }
/** /**
...@@ -422,7 +428,8 @@ object ConfigUtils extends Logging { ...@@ -422,7 +428,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionDouble(value: ConfigValue): Option[Double] = { implicit def configValue2optionDouble(value: ConfigValue): Option[Double] = {
if (value != null && value.value != null && value.value != None) Option(any2double(value.value)) else None if (value != null && value.value != null && value.value != None) Option(any2double(value.value))
else None
} }
/** /**
...@@ -441,7 +448,8 @@ object ConfigUtils extends Logging { ...@@ -441,7 +448,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionFloat(value: ConfigValue): Option[Float] = { implicit def configValue2optionFloat(value: ConfigValue): Option[Float] = {
if (value != null && value.value != null && value.value != None) Option(any2float(value.value)) else None if (value != null && value.value != null && value.value != None) Option(any2float(value.value))
else None
} }
/** /**
...@@ -460,7 +468,8 @@ object ConfigUtils extends Logging { ...@@ -460,7 +468,8 @@ object ConfigUtils extends Logging {
* @return * @return
*/ */
implicit def configValue2optionBoolean(value: ConfigValue): Option[Boolean] = { implicit def configValue2optionBoolean(value: ConfigValue): Option[Boolean] = {
if (value != null && value.value != null && value.value != None) Option(any2boolean(value.value)) else None if (value != null && value.value != null && value.value != None) Option(any2boolean(value.value))
else None
} }
/** /**
......
...@@ -235,10 +235,14 @@ class ConfigUtilsTest extends TestNGSuite with Matchers { ...@@ -235,10 +235,14 @@ class ConfigUtilsTest extends TestNGSuite with Matchers {
} }
var string: String = ConfigValue(index, index, "test") var string: String = ConfigValue(index, index, "test")
string = ConfigValue(index, index, null) intercept[IllegalStateException] {
string = ConfigValue(index, index, null)
}
var file: File = ConfigValue(index, index, "test") var file: File = ConfigValue(index, index, "test")
file = ConfigValue(index, index, null) intercept[IllegalStateException] {
file = ConfigValue(index, index, null)
}
} }
} }
} }
......
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