diff options
author | Arthur Rand <arand@ucsc.edu> | 2018-02-08 18:14:23 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-08 18:14:23 -0800 |
commit | df887f74ff73e3ba5352391dce5843806eb300e6 (patch) | |
tree | f5d921e154f54ae8c1f28ea8b10db458951d5a88 /src/test | |
parent | e848f3822e934e1656b2008dc956b50fa53cc20a (diff) | |
parent | bcfed5f3817ae28053fe6479a106a48205eeffa2 (diff) | |
download | driver-core-df887f74ff73e3ba5352391dce5843806eb300e6.tar.gz driver-core-df887f74ff73e3ba5352391dce5843806eb300e6.tar.bz2 driver-core-df887f74ff73e3ba5352391dce5843806eb300e6.zip |
Merge pull request #109 from drivergroup/api-1252-generalize-db-errors
[API-1252] Add general method for checking for database errors
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/scala/xyz/driver/core/database/DatabaseTest.scala | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/test/scala/xyz/driver/core/database/DatabaseTest.scala b/src/test/scala/xyz/driver/core/database/DatabaseTest.scala index dafcd80..a5c65ea 100644 --- a/src/test/scala/xyz/driver/core/database/DatabaseTest.scala +++ b/src/test/scala/xyz/driver/core/database/DatabaseTest.scala @@ -2,13 +2,27 @@ package xyz.driver.core.database import org.scalatest.{FlatSpec, Matchers} import org.scalatest.prop.Checkers +import xyz.driver.core.rest.errors.DatabaseException class DatabaseTest extends FlatSpec with Matchers with Checkers { + import xyz.driver.core.generators._ "Date SQL converter" should "correctly convert back and forth to SQL dates" in { - import xyz.driver.core.generators.nextDate - for (date <- 1 to 100 map (_ => nextDate())) { sqlDateToDate(dateToSqlDate(date)) should be(date) } } + + "Converter helper methods" should "work correctly" in { + object TestConverter extends Converters + + val validLength = nextInt(10) + val valid = nextToken(validLength) + val invalid = nextToken(validLength + nextInt(10, 1)) + def mapper(s: String): Option[String] = if (s.length == validLength) Some(s) else None + + TestConverter.fromStringOrThrow(valid, mapper, valid) should be(valid) + TestConverter.expectValid(mapper, valid) should be(valid) + an[DatabaseException] should be thrownBy TestConverter.fromStringOrThrow(invalid, mapper, invalid) + } + } |