forked from ceedubs/ficus
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13d8365
commit ab58cb3
Showing
4 changed files
with
56 additions
and
0 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
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
16 changes: 16 additions & 0 deletions
16
src/main/scala/net/ceedubs/ficus/readers/ChronoUnitReader.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,16 @@ | ||
package net.ceedubs.ficus.readers | ||
|
||
import com.typesafe.config.Config | ||
|
||
import java.time.temporal.ChronoUnit | ||
|
||
trait ChronoUnitReader { | ||
implicit val chronoUnitReader: ValueReader[ChronoUnit] = new ValueReader[ChronoUnit] { | ||
|
||
/** Reads the value at the path `path` in the Config */ | ||
override def read(config: Config, path: String): ChronoUnit = | ||
ChronoUnit.valueOf(config.getString(path).toUpperCase) | ||
} | ||
} | ||
|
||
object ChronoUnitReader extends ChronoUnitReader |
38 changes: 38 additions & 0 deletions
38
src/test/scala/net/ceedubs/ficus/readers/ChronoUnitReaderSpec.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,38 @@ | ||
package net.ceedubs.ficus | ||
package readers | ||
|
||
import java.time.temporal.ChronoUnit | ||
|
||
import com.typesafe.config.ConfigFactory | ||
import Ficus.{chronoUnitReader, toFicusConfig} | ||
|
||
class ChronoUnitReaderSpec extends Spec { | ||
def is = s2""" | ||
The ChronoUnitReader should | ||
read a ChronoUnit $readChronoUnit | ||
read a lower case ChronoUnit $readChronoUnitLowerCase | ||
""" | ||
|
||
def readChronoUnit = { | ||
val cfg = ConfigFactory.parseString(s""" | ||
| foo { | ||
| chrono-unit = "MILLIS" | ||
| } | ||
""".stripMargin) | ||
val chronoUnit = cfg.as[ChronoUnit]("foo.chrono-unit") | ||
val expected = ChronoUnit.MILLIS | ||
chronoUnit should_== expected | ||
} | ||
|
||
def readChronoUnitLowerCase = { | ||
val cfg = ConfigFactory.parseString(s""" | ||
| foo { | ||
| chrono-unit = "millis" | ||
| } | ||
""".stripMargin) | ||
val chronoUnit = cfg.as[ChronoUnit]("foo.chrono-unit") | ||
val expected = ChronoUnit.MILLIS | ||
chronoUnit should_== expected | ||
} | ||
|
||
} |