Skip to content

Commit 4773a92

Browse files
Upgraded Scala version to 2.13
1 parent 5584520 commit 4773a92

File tree

7 files changed

+38
-17
lines changed

7 files changed

+38
-17
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ before_install:
1919
tar xv -C travis -f travis/secrets.tar;
2020
fi
2121
script:
22-
- sbt clean coverage test coverageReport &&
23-
sbt coverageAggregate &&
24-
sbt coveralls &&
22+
- sbt clean coverage test &&
23+
sbt coverageAggregate coveralls &&
2524
if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" -o "$TRAVIS_BRANCH" == "$TRAVIS_TAG" ]; then
2625
if [ -z "$TRAVIS_TAG" ]; then
2726
echo "Publish a snapshot";

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[![Build Status](https://travis-ci.com/scommons/scommons-api.svg?branch=master)](https://travis-ci.com/scommons/scommons-api)
33
[![Coverage Status](https://coveralls.io/repos/github/scommons/scommons-api/badge.svg?branch=master)](https://coveralls.io/github/scommons/scommons-api?branch=master)
4-
[![scala-index](https://index.scala-lang.org/scommons/scommons-api/scommons-api-core/latest.svg)](https://index.scala-lang.org/scommons/scommons-api/scommons-api-core)
4+
[![scala-index](https://index.scala-lang.org/scommons/scommons-api/scommons-api-core/latest-by-scala-version.svg?targetType=Js)](https://index.scala-lang.org/scommons/scommons-api/scommons-api-core)
55
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-0.6.29.svg)](https://www.scala-js.org)
66

77
## scommons-api

core/src/main/scala/scommons/api/http/ApiHttpResponse.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package scommons.api.http
22

3+
import scala.collection.immutable.ArraySeq
4+
35
class ApiHttpResponse(val url: String,
46
val status: Int,
5-
val headers: Map[String, Seq[String]],
7+
val headers: Map[String, scala.collection.Seq[String]],
68
getBody: => String,
79
getBodyAsBytes: => Seq[Byte]) {
810

@@ -15,7 +17,11 @@ class ApiHttpResponse(val url: String,
1517

1618
object ApiHttpResponse {
1719

18-
def apply(url: String, status: Int, headers: Map[String, Seq[String]], body: String): ApiHttpResponse = {
19-
new ApiHttpResponse(url, status, headers, body, body.getBytes)
20+
def apply(url: String,
21+
status: Int,
22+
headers: Map[String, scala.collection.Seq[String]],
23+
body: String): ApiHttpResponse = {
24+
25+
new ApiHttpResponse(url, status, headers, body, ArraySeq.unsafeWrapArray(body.getBytes))
2026
}
2127
}

core/src/test/scala/scommons/api/http/ApiHttpClientSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ class ApiHttpClientSpec extends AsyncFlatSpec
181181

182182
//then
183183
inside(ex) { case ApiHttpStatusException(error, resp) =>
184-
error shouldBe {
185-
"Fail to parse http response, error: List((/name,List(JsonValidationError(List(error.path.missing),WrappedArray()))))"
184+
error should startWith {
185+
"Fail to parse http response, error: List((/name,List(JsonValidationError(List(error.path.missing)"
186186
}
187187
resp shouldBe response
188188
}

play-ws/src/test/scala/scommons/api/http/ws/WsApiHttpClientSpec.scala

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package scommons.api.http.ws
22

33
import java.net.URLEncoder
44
import java.util.concurrent.TimeoutException
5-
65
import akka.actor.ActorSystem
76
import akka.stream.ActorMaterializer
87
import akka.util.ByteString
@@ -14,7 +13,7 @@ import org.scalatest.concurrent.ScalaFutures
1413
import org.scalatest.flatspec.AnyFlatSpec
1514
import org.scalatest.matchers.should.Matchers
1615
import org.scalatest.time.{Millis, Seconds, Span}
17-
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
16+
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Inside}
1817
import org.scalatestplus.mockito.MockitoSugar
1918
import play.api.libs.ws.ahc.StandaloneAhcWSClient
2019
import play.api.libs.ws.{EmptyBody, InMemoryBody, StandaloneWSRequest, StandaloneWSResponse}
@@ -26,6 +25,7 @@ import scala.concurrent.{ExecutionContext, Future}
2625

2726
class WsApiHttpClientSpec extends AnyFlatSpec
2827
with Matchers
28+
with Inside
2929
with BeforeAndAfterAll
3030
with BeforeAndAfterEach
3131
with MockitoSugar
@@ -58,7 +58,7 @@ class WsApiHttpClientSpec extends AnyFlatSpec
5858
private val timeout = 5.seconds
5959

6060
override protected def beforeEach(): Unit = {
61-
reset(client, response)
61+
reset[AnyRef](client, response)
6262
}
6363

6464
override protected def afterEach(): Unit = {
@@ -82,7 +82,9 @@ class WsApiHttpClientSpec extends AnyFlatSpec
8282
when(response.bodyAsBytes).thenReturn(ByteString.apply(expectedResult.body))
8383

8484
//when
85-
val Some(result) = client.execute("GET", targetUrl, params, headers, body, timeout).futureValue
85+
val result = inside(client.execute("GET", targetUrl, params, headers, body, timeout).futureValue) {
86+
case Some(res) => res
87+
}
8688

8789
//then
8890
assertApiHttpResponse(result, expectedResult)
@@ -108,7 +110,9 @@ class WsApiHttpClientSpec extends AnyFlatSpec
108110
when(response.bodyAsBytes).thenReturn(ByteString.apply(expectedResult.body))
109111

110112
//when
111-
val Some(result) = client.execute("POST", targetUrl, params, headers, body, timeout).futureValue
113+
val result = inside(client.execute("POST", targetUrl, params, headers, body, timeout).futureValue) {
114+
case Some(res) => res
115+
}
112116

113117
//then
114118
assertApiHttpResponse(result, expectedResult)
@@ -134,7 +138,9 @@ class WsApiHttpClientSpec extends AnyFlatSpec
134138
when(response.bodyAsBytes).thenReturn(ByteString.apply(expectedResult.body))
135139

136140
//when
137-
val Some(result) = client.execute("POST", targetUrl, params, headers, body, timeout).futureValue
141+
val result = inside(client.execute("POST", targetUrl, params, headers, body, timeout).futureValue) {
142+
case Some(res) => res
143+
}
138144

139145
//then
140146
assertApiHttpResponse(result, expectedResult)
@@ -163,7 +169,9 @@ class WsApiHttpClientSpec extends AnyFlatSpec
163169
when(response.bodyAsBytes).thenReturn(ByteString.apply(expectedResult.body))
164170

165171
//when
166-
val Some(result) = client.execute("POST", targetUrl, params, headers, body, timeout).futureValue
172+
val result = inside(client.execute("POST", targetUrl, params, headers, body, timeout).futureValue) {
173+
case Some(res) => res
174+
}
167175

168176
//then
169177
assertApiHttpResponse(result, expectedResult)

project/plugins.sbt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositor
33

44
addSbtPlugin(("org.scommons.sbt" % "sbt-scommons-plugin" % "0.5.0-SNAPSHOT").changing())
55
//addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin" % "0.5.0")
6+
7+
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.5")
8+
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
9+
10+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
11+
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.7")

xhr/src/main/scala/scommons/api/http/xhr/XhrApiHttpClient.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import scommons.api.http.ApiHttpData._
44
import scommons.api.http.xhr.XhrApiHttpClient._
55
import scommons.api.http.{ApiHttpClient, ApiHttpData, ApiHttpResponse}
66

7+
import scala.collection.immutable.ArraySeq
78
import scala.concurrent.duration._
89
import scala.concurrent.{Future, Promise}
910
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
@@ -85,7 +86,8 @@ object XhrApiHttpClient {
8586
if (response == null || js.isUndefined(response)) Nil
8687
else {
8788
//TODO: handle Blob response as well
88-
new Int8Array(response.asInstanceOf[ArrayBuffer]).toArray
89+
val resArr = new Int8Array(response.asInstanceOf[ArrayBuffer]).toArray
90+
ArraySeq.unsafeWrapArray(resArr)
8991
}
9092
}
9193

0 commit comments

Comments
 (0)