Skip to content

Commit 86c7ce3

Browse files
authored
Merge pull request #2984 from broadinstitute/ks_common_100_again
Make Common 100% again.
2 parents b4337a5 + 4a519b1 commit 86c7ce3

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

common/src/test/scala/common/util/VersionUtilSpec.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ class VersionUtilSpec extends FlatSpec with Matchers {
1717
}
1818
}
1919

20+
it should "getVersion with the default" in {
21+
val version = VersionUtil.getVersion("made-up-artifact")
22+
version should be ("made-up-artifact-version.conf-to-be-generated-by-sbt")
23+
}
24+
25+
it should "getVersion with a default override" in {
26+
val version = VersionUtil.getVersion("made-up-artifact", _ => "default override")
27+
version should be ("default override")
28+
}
29+
2030
it should "defaultMessage" in {
2131
VersionUtil.defaultMessage("some-project") should be("some-project-version.conf-to-be-generated-by-sbt")
2232
}

common/src/test/scala/common/validation/ValidationSpec.scala

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package common.validation
22

33
import java.net.URL
44

5-
import cats.data.NonEmptyList
65
import cats.data.Validated.{Invalid, Valid}
6+
import cats.data.{NonEmptyList, ValidatedNel}
77
import cats.syntax.validated._
88
import com.typesafe.config.ConfigFactory
99
import common.exception.AggregatedMessageException
@@ -49,6 +49,21 @@ class ValidationSpec extends FlatSpec with Matchers with Mockito {
4949
url.getPath should be("/world")
5050
}
5151

52+
it should "convert a valid to a successful future" in {
53+
val nel: ValidatedNel[String, String] = "ok".valid
54+
val actual = nel.toFuture(_ => throw new RuntimeException("Should not be used"))
55+
actual.value should be(Option(Success("ok")))
56+
}
57+
58+
it should "convert a invalidNel to an unsuccessful future" in {
59+
val nel: ValidatedNel[String, String] = "failed".invalidNel
60+
val actual = nel.toFuture(nel => new RuntimeException(nel.toList.mkString("processed ", ",", " and caught")))
61+
actual.value match {
62+
case Some(Failure(exception: RuntimeException)) => exception.getMessage should be("processed failed and caught")
63+
case other => fail(s"expected message: 'processed failed and caught' but got '$other'")
64+
}
65+
}
66+
5267
it should "succeed to validate a valid value" in {
5368
val result = validate("hello")
5469
result should be("hello".valid)
@@ -85,4 +100,20 @@ class ValidationSpec extends FlatSpec with Matchers with Mockito {
85100
exception.errorMessages should contain theSameElementsAs List(":(")
86101
}
87102

103+
it should "convert a Some to an ErrorOr" in {
104+
Option("ok").toErrorOr("not used") should be("ok".valid)
105+
}
106+
107+
it should "convert a None to an ErrorOr" in {
108+
None.toErrorOr("error message") should be("error message".invalidNel)
109+
}
110+
111+
it should "convert a Some to an Checked" in {
112+
Option("ok").toChecked("not used") should be(Right("ok"))
113+
}
114+
115+
it should "convert a None to an Checked" in {
116+
None.toChecked("error message") should be(Left(NonEmptyList.one("error message")))
117+
}
118+
88119
}

0 commit comments

Comments
 (0)