Skip to content

Commit

Permalink
problem: altought mima does not complain, Artifact is not backwards c…
Browse files Browse the repository at this point in the history
…ompatible because Option[URI] and Option[URL] erase to Option...
  • Loading branch information
jtjeferreira committed May 22, 2024
1 parent 38bb2e6 commit 73c1265
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions core/src/test/scala/sbt/librarymanagement/ArtifactTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,50 @@ package sbt.librarymanagement

import sjsonnew.support.scalajson.unsafe.{ CompactPrinter, Converter, Parser }

import java.net.URI
import java.net.{ URI, URL }

object ArtifactTest extends verify.BasicTestSuite {

test("it should format itself into JSON") {
import LibraryManagementCodec._
val json = Converter.toJson(Artifact("scala-library").withUri(Some(new URI("")))).get
val json = Converter.toJson(Artifact("scala-library").withUri(Some(new URI("http:/")))).get
assert(CompactPrinter(json) == expectedJson)
}

test("it should thaw back from JSON") {
import LibraryManagementCodec._
val json = Parser.parseUnsafe(expectedJson)
val m = Converter.fromJsonUnsafe[Artifact](json)
assert(m == Artifact("scala-library").withUri(Some(new URI(""))))
assert(m == Artifact("scala-library").withUri(Some(new URI("http:/"))))
}

test("it should be backwards compatible") {
assert(
Artifact(
"scala-library",
"jar",
"jar",
None,
Vector.empty,
Some(new URI("http:/")),
Map.empty,
None,
false
) ==
Artifact(
"scala-library",
"jar",
"jar",
None,
Vector.empty,
Some(new URL("http:/")),
Map.empty,
None,
false
)
)
}

def expectedJson =
"""{"name":"scala-library","type":"jar","extension":"jar","configurations":[],"url":"","extraAttributes":{},"allowInsecureProtocol":false}"""
"""{"name":"scala-library","type":"jar","extension":"jar","configurations":[],"url":"http:/","extraAttributes":{},"allowInsecureProtocol":false}"""
}

0 comments on commit 73c1265

Please sign in to comment.