forked from finos/vuu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finos#1296 add 3 more default type converters + tests for DefaultType…
…Converters
- Loading branch information
1 parent
e1858bd
commit af4772c
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
vuu/src/test/scala/org/finos/vuu/util/schema/typeConversion/DefaultTypeConvertersTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.finos.vuu.util.schema.typeConversion | ||
|
||
import org.finos.vuu.util.schema.typeConversion.DefaultTypeConverters._ | ||
import org.scalatest.prop.TableDrivenPropertyChecks._ | ||
import org.scalatest.featurespec.AnyFeatureSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class DefaultTypeConvertersTest extends AnyFeatureSpec with Matchers { | ||
|
||
Feature("Handle converting valid value to the given type") { | ||
|
||
forAll(Table( | ||
("title", "converter", "input", "expected output"), | ||
("String to Double", stringToDoubleConverter, "10.5", 10.5), | ||
("Double to String", doubleToStringConverter, 10.5, "10.5"), | ||
("String to Long", stringToLongConverter, "10000", 10_000L), | ||
("Long to String", longToStringConverter, 10_000L, "10000"), | ||
("Int to String", intToStringConverter, 10, "10"), | ||
("String to Int", stringToIntConverter, "10", 10), | ||
))((title, converter, input, expectedOutput) => { | ||
Scenario(title) { | ||
converter.asInstanceOf[TypeConverter[Any, Any]].convert(input) shouldEqual expectedOutput | ||
} | ||
}) | ||
} | ||
|
||
Feature("Handle null inputs") { | ||
forAll(Table( | ||
("title", "converter"), | ||
("String to Double", stringToDoubleConverter), | ||
("Double to String", doubleToStringConverter), | ||
("String to Long", stringToLongConverter), | ||
("Long to String", longToStringConverter), | ||
("Int to String", intToStringConverter), | ||
("String to Int", stringToIntConverter), | ||
))((title, converter) => { | ||
Scenario(title) { | ||
converter.convert(null) shouldEqual null | ||
} | ||
}) | ||
} | ||
|
||
} |