diff options
author | adamw <adam@warski.org> | 2017-11-27 12:50:52 +0100 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-11-27 12:50:52 +0100 |
commit | b6d01181152ca11747ec5d2feabfa3621d61f73c (patch) | |
tree | afd6b0bd6a10a4d4e13008437a1bf1897eba2943 /core/src/test/scala/com | |
parent | 8cf5bdc708a46fa9e842481db54caaf59123e4e6 (diff) | |
download | sttp-b6d01181152ca11747ec5d2feabfa3621d61f73c.tar.gz sttp-b6d01181152ca11747ec5d2feabfa3621d61f73c.tar.bz2 sttp-b6d01181152ca11747ec5d2feabfa3621d61f73c.zip |
Validating that the port is specified only once when interpolating a URI
Diffstat (limited to 'core/src/test/scala/com')
-rw-r--r-- | core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala | 27 | ||||
-rw-r--r-- | core/src/test/scala/com/softwaremill/sttp/UriTests.scala | 2 |
2 files changed, 25 insertions, 4 deletions
diff --git a/core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala b/core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala index 92c90c3..f8d32ed 100644 --- a/core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala +++ b/core/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala @@ -71,8 +71,7 @@ class UriInterpolatorTests extends FunSuite with Matchers { (uri"http://example.com:${8080}/x", s"http://example.com:8080/x"), (uri"http://example.com:${Some(8080)}/x", s"http://example.com:8080/x"), (uri"http://example.com:$None/x", s"http://example.com/x"), - (uri"http://${"example.com:8080"}", s"http://example.com:8080"), - (uri"http://${"example.com:8080"}:$None", s"http://example.com:8080") + (uri"http://${"example.com:8080"}", s"http://example.com:8080") ), "path" -> List( (uri"http://example.com/$v1", s"http://example.com/$v1"), @@ -145,8 +144,30 @@ class UriInterpolatorTests extends FunSuite with Matchers { (groupName, testCases) <- testData ((interpolated, expected), i) <- testCases.zipWithIndex } { - test(s"[$groupName] interpolate to $expected (${i + 1})") { + test(s"[$groupName] should interpolate to $expected (${i + 1})") { interpolated.toString should be(expected) } } + + val validationTestData = List( + ("uri with two ports", + () => uri"http://example.com:80:80", + "port specified multiple times"), + ("uri with embedded host+port and port", + () => uri"http://${"example.com:80"}:80", + "port specified multiple times") + ) + + for { + (name, createUri, expectedException) <- validationTestData + } { + test( + s"""$name should validate and throw "$expectedException" if not valid""") { + val caught = intercept[IllegalArgumentException] { + createUri() + } + + caught.getMessage.toLowerCase() should include(expectedException) + } + } } diff --git a/core/src/test/scala/com/softwaremill/sttp/UriTests.scala b/core/src/test/scala/com/softwaremill/sttp/UriTests.scala index 73cb05d..b94ac72 100644 --- a/core/src/test/scala/com/softwaremill/sttp/UriTests.scala +++ b/core/src/test/scala/com/softwaremill/sttp/UriTests.scala @@ -145,7 +145,7 @@ class UriTests extends FunSuite with Matchers { for { (createUri, expectedException) <- validationTestData } { - test(s"""should validate URI and throw "$expectedException" if not valid""") { + test(s"""should validate and throw "$expectedException" if not valid""") { val caught = intercept[IllegalArgumentException] { createUri() } |