From 6beb8f2c85be3f73a5605f823a608a04331f0248 Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Fri, 8 Apr 2016 13:29:55 +0200 Subject: [PATCH] Tests for FakeResolver --- ivy/src/test/resources/artifact1.jar | Bin 0 -> 313 bytes ivy/src/test/resources/artifact2.txt | 0 .../scala/FakeResolverSpecification.scala | 67 ++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 ivy/src/test/resources/artifact1.jar create mode 100644 ivy/src/test/resources/artifact2.txt create mode 100644 ivy/src/test/scala/FakeResolverSpecification.scala diff --git a/ivy/src/test/resources/artifact1.jar b/ivy/src/test/resources/artifact1.jar new file mode 100644 index 0000000000000000000000000000000000000000..be043359eecf5f14458fb95d21a04b9bcd94a4e4 GIT binary patch literal 313 zcmWIWW@Zs#U|`^25O(bFaM{qyG!@9(0L1JJG7J%V$vKI|#i1db49rix*u$RzacKoN z10%~gt7+KnxZ_pE^%o7nR| zQ$pO>>gJ!>6SDu(oh4TmO*pbdW&uZdL0x8G(W+>*j>BRLr%#QTcH;1XLkCWsI3RKG zgaX5(*Uwd+Eq(o4J$0$tbOQ||1ID+Ej0?CXI4PWDdvdbrClAk>sN0ef=1og)HmXQR z2&f!oTryL_f-%6Gkx7mjm%k){zJq`zjUXECOIC<4(R>)-&B_K+#t4MIK>8Yp!vFwy C*jvj0 literal 0 HcmV?d00001 diff --git a/ivy/src/test/resources/artifact2.txt b/ivy/src/test/resources/artifact2.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ivy/src/test/scala/FakeResolverSpecification.scala b/ivy/src/test/scala/FakeResolverSpecification.scala new file mode 100644 index 000000000..baed9cc28 --- /dev/null +++ b/ivy/src/test/scala/FakeResolverSpecification.scala @@ -0,0 +1,67 @@ +package sbt + +import java.io.File + +import org.specs2._ + +class FakeResolverSpecification extends BaseIvySpecification { + import FakeResolver._ + + def is = s2""" + This is a specification for the FakeResolver + + The FakeResolver should + find modules with only one artifact $singleArtifact + find modules with more than one artifact $multipleArtifacts + """ + + val myModule = ModuleID("org.example", "my-module", "0.0.1-SNAPSHOT", Some("compile")) + val example = ModuleID("com.example", "example", "1.0.0", Some("compile")) + + def singleArtifact = { + val m = getModule(myModule) + val report = ivyUpdate(m) + val allFiles = getAllFiles(report) + + report.allModules should haveLength(1) + report.configurations should haveLength(3) + allFiles should haveLength(1) + allFiles(1).getName should beEqualTo("artifact1-0.0.1-SNAPSHOT.jar") + } + + def multipleArtifacts = { + val m = getModule(example) + val report = ivyUpdate(m) + val allFiles = getAllFiles(report).toSet + + report.allModules should haveLength(1) + report.configurations should haveLength(3) + allFiles should haveLength(2) + allFiles map (_.getName) should beEqualTo(Set("artifact1-1.0.0.jar", "artifact2-1.0.0.txt")) + } + + private def artifact1 = new File(getClass.getResource("/artifact1.jar").toURI.getPath) + private def artifact2 = new File(getClass.getResource("/artifact2.txt").toURI.getPath) + + private def modules = Map( + ("org.example", "my-module", "0.0.1-SNAPSHOT") -> List( + FakeArtifact("artifact1", "jar", "jar", artifact1) + ), + + ("com.example", "example", "1.0.0") -> List( + FakeArtifact("artifact1", "jar", "jar", artifact1), + FakeArtifact("artifact2", "txt", "txt", artifact2) + ) + ) + + private def fakeResolver = new FakeResolver("FakeResolver", new File("tmp"), modules) + override def resolvers: Seq[Resolver] = Seq(new RawRepository(fakeResolver)) + private def getModule(myModule: ModuleID): IvySbt#Module = module(defaultModuleId, Seq(myModule), None) + private def getAllFiles(report: UpdateReport) = + for { + conf <- report.configurations + m <- conf.modules + (_, f) <- m.artifacts + } yield f + +} \ No newline at end of file