Skip to content

Commit

Permalink
-- mockito
Browse files Browse the repository at this point in the history
  • Loading branch information
djnzx committed Dec 12, 2024
1 parent 94721cf commit 980517d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
26 changes: 26 additions & 0 deletions ce3/src/main/scala/mockitox/LearningMockitoSpy.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package mockitox

import org.mockito.IdiomaticMockito
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

class LearningMockitoSpy extends AnyFunSuite with Matchers with IdiomaticMockito {

class Calculator {
def add0(a: Int, b: Int): Int = a + b
def add(a: Int, b: Int): Int = add0(a, b)

def sub(a: Int, b: Int): Int = a - b
}

val realCalculator = new Calculator
val spyCalculator = spy(realCalculator)

test("1") {
spyCalculator.add0(1, 2).returns(113)

val x = spyCalculator.add(1, 2)
pprint.log(x) // 113
}

}
11 changes: 7 additions & 4 deletions plain2/src/main/scala/winitzki/Fundamentals6.scala
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,11 @@ class Fundamentals6 extends Base {
def durationToLong: FiniteDuration => Long = _.toNanos

// now we can derive Semigroup[FiniteDuration] (profunctor)
val combiner = Invariant[Semigroup].imap(combinerLong)(longToDuration)(durationToLong)
val combiner: Semigroup[FiniteDuration] = Invariant[Semigroup].imap(combinerLong)(longToDuration)(durationToLong)

import scala.concurrent.duration._
// it takes type A, converts to B, does B |+| B, converts to A back
val combined: FiniteDuration = combiner.combine(2.seconds, 3.seconds)
val combined1: FiniteDuration = combiner.combine(2.seconds, 3.seconds)
val combined2: FiniteDuration = 2.seconds |+| 3.seconds

sealed trait List[A]
final case class Empty[A]() extends List[A]
Expand Down Expand Up @@ -513,5 +513,8 @@ class Fundamentals6 extends Base {
h2(3) shouldBe 301
}

test("6.2.6.4 - p 204") {}
test("6.2.4 - p 204 ???") {
type Const[Z, A] = Z
def cmap[Z, A, B](f: B => A): Const[Z, A] => Const[Z, B] = identity[Z]
}
}
15 changes: 6 additions & 9 deletions project/Libraries.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ object Libraries {
val newtype = "io.estatico" %% "newtype" % "0.4.4"
val refinedCore = "eu.timepit" %% "refined" % "0.10.3"
val refinedCats = "eu.timepit" %% "refined-cats" % "0.10.3"
val refinedScalaz = "eu.timepit" %% "refined-scalaz" % "0.10.3"
// basic functional abstractions
val cats = "org.typelevel" %% "cats-core" % "2.10.0"
val catsLaws = "org.typelevel" %% "cats-laws" % "2.10.0"
Expand All @@ -23,26 +22,24 @@ object Libraries {
val logback = "ch.qos.logback" % "logback-classic" % "1.4.7"
// https://scalacheck.org
// https://mvnrepository.com/artifact/org.scalacheck/scalacheck
val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.17.0"
val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.18.1"
// https://www.scalatest.org
// https://mvnrepository.com/artifact/org.scalatest/scalatest
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.17"
val scalaTestShould = "org.scalatest" %% "scalatest-shouldmatchers" % "3.2.17"
val scalaTestFunSpec = "org.scalatest" %% "scalatest-funspec" % "3.2.17"
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.19"
// https://github.com/alexarchambault/scalacheck-shapeless
val scalaCheckShapeless = "com.github.alexarchambault" %% "scalacheck-shapeless_1.16" % "1.3.1"
// https://www.scalactic.org
// https://mvnrepository.com/artifact/org.scalactic/scalactic
// val scalactic_ = "org.scalactic" %% "scalactic" % Versions.scalaTest
val scalaCheckIntegration = "org.scalatestplus" %% "scalacheck-1-17" % "3.2.17.0"
val scalaMockito = "org.mockito" %% "mockito-scala-scalatest" % "1.17.30" // tr: "org.mockito" % "mockito-core" % "4.8.1"
val scalaCheckIntegration = "org.scalatestplus" %% "scalacheck-1-18" % "3.2.19.0"
val scalaMockito = "org.mockito" %% "mockito-scala-scalatest" % "1.17.37" // tr: "org.mockito" % "mockito-core" % "4.8.1"
// https://index.scala-lang.org/ghik/silencer/silencer-plugin/1.4.2?target=_2.13
// look for the plugin corresponding
val silencerAnnotation = "com.github.ghik" % "silencer-lib" % "1.6.0" % Provided cross CrossVersion.full

val testingToolkit2: Seq[ModuleID] = Seq(
scalaTest, // runners, matchers
scalaCheck, // property based testing
scalaCheck, // property-based testing
scalaCheckIntegration, // scalaTest integration
scalaCheckShapeless, // Shapeless scalacheck Arbitrary[A] derivation, doesn't have scala3 things
scalaMockito, // mock traits/classes, doesn't have scala3 things
Expand All @@ -51,7 +48,7 @@ object Libraries {

val testingToolkit3: Seq[ModuleID] = Seq(
scalaTest, // runners, matchers
scalaCheck, // property based testing
scalaCheck, // property-based testing
scalaCheckIntegration, // scalaTest integration
LibrariesLihaoyi.pprint // println colored + colored console output + implicits to get source module/file/line/etc
)
Expand Down
20 changes: 10 additions & 10 deletions project/LibrariesLihaoyi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import sbt.*

object LibrariesLihaoyi {

val fansi = "com.lihaoyi" %% "fansi" % "0.4.0"
val pprint = "com.lihaoyi" %% "pprint" % "0.8.1"
val sourcecode = "com.lihaoyi" %% "sourcecode" % "0.3.0"
val upickle = "com.lihaoyi" %% "upickle" % "3.1.2" // http://www.lihaoyi.com/upickle
val ujson = "com.lihaoyi" %% "ujson" % "3.1.2"
val osLib = "com.lihaoyi" %% "os-lib" % "0.9.1"
val scalatags = "com.lihaoyi" %% "scalatags" % "0.12.0"
val requests = "com.lihaoyi" %% "requests" % "0.8.0"
val geny = "com.lihaoyi" %% "geny" % "1.0.0"
val fastparse = "com.lihaoyi" %% "fastparse" % "3.0.2" // https://www.lihaoyi.com/fastparse/
val fansi = "com.lihaoyi" %% "fansi" % "0.5.0"
val pprint = "com.lihaoyi" %% "pprint" % "0.9.0"
val sourcecode = "com.lihaoyi" %% "sourcecode" % "0.4.2"
val upickle = "com.lihaoyi" %% "upickle" % "4.0.2" // http://www.lihaoyi.com/upickle
val ujson = "com.lihaoyi" %% "ujson" % "4.0.2"
val osLib = "com.lihaoyi" %% "os-lib" % "0.11.3"
val scalatags = "com.lihaoyi" %% "scalatags" % "0.13.1"
val requests = "com.lihaoyi" %% "requests" % "0.9.0"
val geny = "com.lihaoyi" %% "geny" % "1.1.1"
val fastparse = "com.lihaoyi" %% "fastparse" % "3.1.1" // https://www.lihaoyi.com/fastparse/

}

0 comments on commit 980517d

Please sign in to comment.