Skip to content

Commit

Permalink
Merge pull request #260 from guardian/fix-scala-2.13-warnings
Browse files Browse the repository at this point in the history
Fix scala 2.13 warnings
  • Loading branch information
davidfurey authored Feb 18, 2022
2 parents 201ef36 + 556fa7d commit d9aad4f
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 78 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def faciaJson_playJsonVersion(majorMinorVersion: String) = baseProject("facia-js
commonsIo,
specs2,
"com.typesafe.play" %% "play-json" % exactPlayJsonVersions(majorMinorVersion),
"org.scala-lang.modules" %% "scala-collection-compat" % "2.6.0",
scalaLogging
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CollectionSpec extends Specification with ResourcesHelper {

collection.live.find(_.id == "football/quiz/2014/jun/11/world-cup-2014-the-ultimate-world-cup-trivia-quiz") must
beSome.which({ front =>
(front.frontPublicationDate mustEqual 1402500092818l) and (front.meta mustEqual Some(TrailMetaData.withDefaults(
(front.frontPublicationDate mustEqual 1402500092818L) and (front.meta mustEqual Some(TrailMetaData.withDefaults(
("headline", JsString("The ultimate World Cup trivia quiz")),
("group", JsString("0"))
)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ConfigSpec extends Specification with ResourcesHelper {
| }""".stripMargin
val parsed = Json.fromJson[CollectionConfigJson](Json.parse(configJson))
parsed.asOpt must beSome.which({ config =>
config.targetedTerritory must beSome(UnknownTerritory)
config.targetedTerritory must be(Some(UnknownTerritory))
})
}

Expand Down
5 changes: 3 additions & 2 deletions fapi-client/src/main/scala/com/gu/facia/api/FAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.gu.facia.api.contentapi.{ContentApi, LatestSnapsRequest, LinkSnapsReq
import com.gu.facia.api.models._
import com.gu.facia.api.utils.BackfillResolver
import com.gu.facia.client.ApiClient
import scala.collection.compat._

import scala.concurrent.{ExecutionContext, Future}

Expand All @@ -20,7 +21,7 @@ object FAPI {

def frontForPath(path: String)(implicit capiClient: ContentApiClient, faciaClient: ApiClient, ec: ExecutionContext): Response[Front] = {
for {
fronts <- getFronts
fronts <- getFronts()
front <- Response.fromOption(fronts.find(_.id == path), NotFound(s"Not front found for $path"))
} yield front
}
Expand Down Expand Up @@ -58,7 +59,7 @@ object FAPI {
)
collectionConfigs = collectionConfigJsons.map(CollectionConfig.fromCollectionJson)
} yield {
(collectionIds, collectionsJsons, collectionConfigs).zipped.toList.map { case (collectionId, collectionJson, collectionConfig) =>
collectionIds.lazyZip(collectionsJsons).lazyZip(collectionConfigs).toList.map { case (collectionId, collectionJson, collectionConfig) =>
Collection.fromCollectionJsonConfigAndContent(collectionId, collectionJson, collectionConfig)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object ContentApi extends StrictLogging {
searchResponses.flatMap(_.results).toSet

def buildBackfillQuery(apiQuery: String): Either[ItemQuery, SearchQuery] = {
val uri = new URI(apiQuery.replaceAllLiterally("|", "%7C").replaceAllLiterally(" ", "%20"))
val uri = new URI(apiQuery.replace("|", "%7C").replace(" ", "%20"))
val path = uri.getPath.stripPrefix("/")
val rawParams = Option(uri.getQuery).map(parseQueryString).getOrElse(Nil).map {
// wrap backfill tags in parentheses in case the editors wrote a raw OR query
Expand Down Expand Up @@ -73,7 +73,7 @@ object ContentApi extends StrictLogging {

def getBackfillResponse(client: ContentApiClient, query: Either[ItemQuery, SearchQuery])
(implicit ec: ExecutionContext): Either[Response[ItemResponse], Response[SearchResponse]] = {
query.right.map { itemQuery =>
query.map { itemQuery =>
Response.Async.Right(client.getResponse(itemQuery)) mapError { err =>
CapiError(s"Failed to get backfill response ${err.message}", err.cause)
}
Expand All @@ -99,7 +99,7 @@ object ContentApi extends StrictLogging {
def parseQueryString(queryString: String): Seq[(String, String)] = {
val KeyValuePair = """([^=]+)=(.*)""".r

queryString split "&" collect {
queryString.split("&").toSeq.collect {
case KeyValuePair(key, value) => (key, value)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object BackfillResolver {
resolver match {
case CapiBackfill(query, collectionConfig) =>
val capiQuery = ContentApi.buildBackfillQuery(query)
.right.map(adjustSearchQuery)
.map(adjustSearchQuery)
.left.map(adjustItemQuery)
val backfillResponse = ContentApi.getBackfillResponse(capiClient, capiQuery)
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ class ContentApiTest extends FreeSpec
}

"should wrap the tag parameter in brackets" in {
val tagParam = ContentApi.buildBackfillQuery(backfill).right.value.parameters.get("tag").value
val tagParam = ContentApi.buildBackfillQuery(backfill).toOption.get.parameters.get("tag").value
tagParam should startWith("(")
tagParam should endWith(")")
}

"adds the internalPageCode field" in {
ContentApi.buildBackfillQuery(backfill).right.value.parameters.get("show-fields").value should equal ("internalPageCode")
ContentApi.buildBackfillQuery(backfill).toOption.get.parameters.get("show-fields").value should equal ("internalPageCode")
}

"preserves existing show-fields when adding internaPageCode" in {
val backfillWithFields = s"$backfill&show-fields=headline"
ContentApi.buildBackfillQuery(backfillWithFields).right.value.parameters.get("show-fields").value should equal ("headline,internalPageCode")
ContentApi.buildBackfillQuery(backfillWithFields).toOption.get.parameters.get("show-fields").value should equal ("headline,internalPageCode")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class IntegrationTest extends FreeSpec with Matchers with ScalaFutures with Opti
"should return the collection with a given id" in {
FAPI.getCollection("uk-alpha/news/regular-stories").asFuture.futureValue.fold(
err => fail(s"expected collection, got $err", err.cause),
collection => collection should have ('id ("uk-alpha/news/regular-stories"))
collection => collection should have (Symbol("id") ("uk-alpha/news/regular-stories"))
)
}
}
Expand All @@ -83,7 +83,7 @@ class IntegrationTest extends FreeSpec with Matchers with ScalaFutures with Opti
}

"should return the curated content for the collection" ignore {
val collection = collectionResponse.right.get
val collection = collectionResponse.toOption.get
FAPI.liveCollectionContentWithSnaps(collection).asFuture.futureValue.fold(
err => fail(s"expected collection, got $err", err.cause),
curatedContent => curatedContent.size should be > 0
Expand All @@ -92,7 +92,7 @@ class IntegrationTest extends FreeSpec with Matchers with ScalaFutures with Opti

"will use the provided function to adjust the query used to hydrate content" ignore {
val adjust: AdjustSearchQuery = q => q.showTags("tone")
val collection = collectionResponse.right.get
val collection = collectionResponse.toOption.get
FAPI.liveCollectionContentWithSnaps(collection, adjust).asFuture.futureValue.fold(
err => fail(s"expected collection, got $err", err.cause),
curatedContent => curatedContent.flatMap{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,23 @@ class CollectionTest extends FreeSpec with Matchers with MockitoSugar with OneIn

"creates a Facia collection from the collection JSON and provided config" in {
collection should have(
'id("id"),
'draft(None),
'href(Some("collectionConfigHref")),
'lastUpdated(Some(new DateTime(1))),
'updatedBy(Some("test")),
'updatedEmail(Some("[email protected]")),
'displayName("displayName")
Symbol("id")("id"),
Symbol("draft")(None),
Symbol("href")(Some("collectionConfigHref")),
Symbol("lastUpdated")(Some(new DateTime(1))),
Symbol("updatedBy")(Some("test")),
Symbol("updatedEmail")(Some("[email protected]")),
Symbol("displayName")("displayName")
)

collection.collectionConfig should have (
'href(Some("collectionConfigHref"))
Symbol("href")(Some("collectionConfigHref"))
)
}

"creates metadata from provided config JSON" in {
collection.collectionConfig should have(
'metadata (Some(List(Branded)))
Symbol("metadata") (Some(List(Branded)))
)
}
}
Expand All @@ -155,7 +155,7 @@ class CollectionTest extends FreeSpec with Matchers with MockitoSugar with OneIn
"Uses content fields when no facia override exists" in {
val curatedContent = Collection.liveContent(collection, contents)
curatedContent.head should have (
'headline ("Content headline")
Symbol("headline") ("Content headline")
)
}

Expand All @@ -167,9 +167,9 @@ class CollectionTest extends FreeSpec with Matchers with MockitoSugar with OneIn

val curatedContent = Collection.liveContent(collection, contents)
curatedContent.head should have (
'headline ("trail headline"),
'href (Some("trail href")),
'kicker (Some(FreeHtmlKicker("Custom kicker")))
Symbol("headline") ("trail headline"),
Symbol("href") (Some("trail href")),
Symbol("kicker") (Some(FreeHtmlKicker("Custom kicker")))
)
}

Expand Down Expand Up @@ -456,7 +456,7 @@ class CollectionTest extends FreeSpec with Matchers with MockitoSugar with OneIn
val result = Collection.liveContent(collection, contents)
result.length should be (1)
result.head should have (
'headline("straight banana")
Symbol("headline")("straight banana")
)
}
"supporting with internalPageCode" in {
Expand All @@ -467,7 +467,7 @@ class CollectionTest extends FreeSpec with Matchers with MockitoSugar with OneIn
val result = Collection.liveContent(collection, contents)
result.length should be (1)
result.head should have (
'headline("straw berry")
Symbol("headline")("straw berry")
)
FaciaContentUtils.headline(FaciaContentUtils.supporting(result.head).head) should be ("straight banana")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,38 @@ class ResolvedMetaDataTest extends FreeSpec with Matchers with TestContent {
"Content with type cartoon should showByline" in {
val resolvedMetaData = ResolvedMetaData.fromContent(contentWithCartoon, DefaultCardstyle)
resolvedMetaData should have (
'showByline (true))
Symbol("showByline") (true))
}

"Content with type comment should showByline, showQuotedHeadline and imageCutoutReplace" in {
val resolvedMetaData = ResolvedMetaData.fromContent(contentWithComment, Comment)
resolvedMetaData should have (
'showByline (true),
'showQuotedHeadline (true),
'imageCutoutReplace (true))
Symbol("showByline") (true),
Symbol("showQuotedHeadline") (true),
Symbol("imageCutoutReplace") (true))
}

"Content with type video should showMainVideo" in {
val resolvedMetaData = ResolvedMetaData.fromContent(contentWithVideo, DefaultCardstyle)
resolvedMetaData should have (
'showMainVideo (true))
Symbol("showMainVideo") (true))
}

"Content with silly type should all false" in {
val contentWithVideo = contentWithTags(tagWithId("sillyid"))
val resolvedMetaData = ResolvedMetaData.fromContent(contentWithVideo, DefaultCardstyle)
resolvedMetaData should have (
'showByline (false),
'showQuotedHeadline (false),
'imageCutoutReplace (false),
'showMainVideo (false),
'isBoosted (false),
'isBreaking (false),
'imageHide (false),
'imageReplace (false),
'showKickerCustom (false),
'showKickerSection (false),
'showKickerTag (false))
Symbol("showByline") (false),
Symbol("showQuotedHeadline") (false),
Symbol("imageCutoutReplace") (false),
Symbol("showMainVideo") (false),
Symbol("isBoosted") (false),
Symbol("isBreaking") (false),
Symbol("imageHide") (false),
Symbol("imageReplace") (false),
Symbol("showKickerCustom") (false),
Symbol("showKickerSection") (false),
Symbol("showKickerTag") (false))
}
}

Expand All @@ -88,33 +88,33 @@ class ResolvedMetaDataTest extends FreeSpec with Matchers with TestContent {
"Resolve all to false for empty TrailMetaData" in {
val resolvedMetaData = ResolvedMetaData.fromTrailMetaData(emptyTrailMetaData)
resolvedMetaData should have (
'showByline (false),
'showQuotedHeadline (false),
'imageCutoutReplace (false),
'showMainVideo (false),
'isBoosted (false),
'isBreaking (false),
'imageHide (false),
'imageReplace (false),
'showKickerCustom (false),
'showKickerSection (false),
'showKickerTag (false))
Symbol("showByline") (false),
Symbol("showQuotedHeadline") (false),
Symbol("imageCutoutReplace") (false),
Symbol("showMainVideo") (false),
Symbol("isBoosted") (false),
Symbol("isBreaking") (false),
Symbol("imageHide") (false),
Symbol("imageReplace") (false),
Symbol("showKickerCustom") (false),
Symbol("showKickerSection") (false),
Symbol("showKickerTag") (false))
}

"Resolve all to true for empty TrailMetaData" in {
val resolvedMetaData = ResolvedMetaData.fromTrailMetaData(trailMetaDataWithFieldsSetTrue)
resolvedMetaData should have (
'showByline (true),
'showQuotedHeadline (true),
'imageCutoutReplace (true),
'showMainVideo (true),
'isBoosted (false),
'isBreaking (false),
'imageHide (false),
'imageReplace (false),
'showKickerCustom (false),
'showKickerSection (false),
'showKickerTag (false)
Symbol("showByline") (true),
Symbol("showQuotedHeadline") (true),
Symbol("imageCutoutReplace") (true),
Symbol("showMainVideo") (true),
Symbol("isBoosted") (false),
Symbol("isBreaking") (false),
Symbol("imageHide") (false),
Symbol("imageReplace") (false),
Symbol("showKickerCustom") (false),
Symbol("showKickerSection") (false),
Symbol("showKickerTag") (false)
)
}
}
Expand All @@ -124,47 +124,47 @@ class ResolvedMetaDataTest extends FreeSpec with Matchers with TestContent {
"should resolve correct for cartoon when trailMetaData is not set" in {
val resolvedCartoon = ResolvedMetaData.fromContentAndTrailMetaData(contentWithCartoon, emptyTrailMetaData, DefaultCardstyle)
resolvedCartoon should have (
'showByline (true))
Symbol("showByline") (true))
}

"should resolve correct for comment when trailMetaData is not set" in {
val resolvedComment = ResolvedMetaData.fromContentAndTrailMetaData(contentWithComment, emptyTrailMetaData, Comment)
resolvedComment should have (
'showByline (true),
'showQuotedHeadline (true),
'imageCutoutReplace (true))
Symbol("showByline") (true),
Symbol("showQuotedHeadline") (true),
Symbol("imageCutoutReplace") (true))
}

"should resolve correct for video when trailMetaData is not set" in {
val resolvedVideo = ResolvedMetaData.fromContentAndTrailMetaData(contentWithVideo, emptyTrailMetaData, DefaultCardstyle)
resolvedVideo should have (
'showMainVideo (true))
Symbol("showMainVideo") (true))
}

"should resolve correct for video with Atom" in {
val resolvedVideo = ResolvedMetaData.fromContentAndTrailMetaData(contentWithAtom, emptyTrailMetaData, DefaultCardstyle)
resolvedVideo should have(
'showMainVideo (true))
Symbol("showMainVideo") (true))
}

"should resolve correct for cartoon when trailMetaData IS set" in {
val resolvedCartoon = ResolvedMetaData.fromContentAndTrailMetaData(contentWithCartoon, trailMetaDataWithFieldsSetFalse, DefaultCardstyle)
resolvedCartoon should have (
'showByline (false))
Symbol("showByline") (false))
}

"should resolve correct for comment when trailMetaData IS set" in {
val resolvedComment = ResolvedMetaData.fromContentAndTrailMetaData(contentWithComment, trailMetaDataWithFieldsSetFalse, DefaultCardstyle)
resolvedComment should have (
'showByline (false),
'showQuotedHeadline (false),
'imageCutoutReplace (false))
Symbol("showByline") (false),
Symbol("showQuotedHeadline") (false),
Symbol("imageCutoutReplace") (false))
}

"should resolve correct for video when trailMetaData IS set" in {
val resolvedVideo = ResolvedMetaData.fromContentAndTrailMetaData(contentWithVideo, trailMetaDataWithFieldsSetFalse, DefaultCardstyle)
resolvedVideo should have (
'showMainVideo (false))
Symbol("showMainVideo") (false))
}
}

Expand Down

0 comments on commit d9aad4f

Please sign in to comment.