-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Added Joda Duration Converter to plugin sample
- Loading branch information
1 parent
c0833d7
commit 27f8045
Showing
3 changed files
with
44 additions
and
5 deletions.
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
11 changes: 7 additions & 4 deletions
11
src/test/scala/dev/mongocamp/driver/mongodb/bson/JodaConverterPlugin.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
36 changes: 36 additions & 0 deletions
36
src/test/scala/dev/mongocamp/driver/mongodb/bson/JodaConverterPluginSpec.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,36 @@ | ||
package dev.mongocamp.driver.mongodb.bson | ||
|
||
import org.joda.time.DateTime | ||
import org.specs2.mutable.Specification | ||
import org.specs2.specification.BeforeAfterAll | ||
|
||
import scala.concurrent.duration.Duration | ||
|
||
class JodaConverterPluginSpec extends Specification with BeforeAfterAll { | ||
|
||
sequential | ||
|
||
"JodaConverterPlugin" should { | ||
|
||
"convert joda dates to bson dates" in { | ||
val dateTime = new DateTime("2023-11-02") | ||
val bsonDocument = BsonConverter.toBson(dateTime) | ||
(bsonDocument.toString must be).equalTo("BsonDateTime{value=1698879600000}") | ||
} | ||
|
||
"convert joda duration to bson string" in { | ||
val duration = org.joda.time.Duration.standardDays(1) | ||
val bsonDocument = BsonConverter.toBson(duration) | ||
(bsonDocument.toString must be).equalTo("BsonString{value='86400000ms'}") | ||
(Duration("86400000ms").toMillis must be).equalTo(duration.getMillis) | ||
} | ||
|
||
} | ||
|
||
override def beforeAll(): Unit = { | ||
BsonConverter.converterPlugin = new JodaConverterPlugin() | ||
} | ||
override def afterAll(): Unit = { | ||
BsonConverter.converterPlugin = new BaseConverterPlugin() | ||
} | ||
} |