Error using Mockito and Specs2 - scala

I have the following spec:
import org.specs2.mock.Mockito
import org.specs2.mutable.Specification
class LinkUserServiceSpec extends Specification with Mockito {
val linkUserService = mock[LinkUserService]
"The 'LinkUserService' isUserLinked method" should {
"return false when a previously unlinked userId is passed in for a given service" in {
linkUserService.isUserLinked("nobody", "YT") returns false
linkUserService.isUserLinked("nobody", "YT") must beFalse
}
}
}
And the following dependency in my build.sbt:
"org.specs2" %% "specs2" % "2.2" % "test"
However I get this error when I type test into the sbt console:
[error] bad symbolic reference. A signature in MocksCreation.class refers to type MockSettings
[error] in package org.mockito which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling MocksCreation.class.
[error] bad symbolic reference. A signature in MockitoStubs.class refers to term stubbing
[error] in package org.mockito which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling MockitoStubs.class.
[error] two errors found
[error] (test:compile) Compilation failed
[error] Total time: 3 s, completed Sep 12, 2013 3:23:41 PM
Anyone know what this could be?

Apparently if you want to use Mockito with Specs2 you have to provide the dependency yourself, I added the following to my build.sbt and things started working:
"org.mockito" % "mockito-all" % "1.9.5"

Related

How to deserialize a protobuf in scala

I have a protobuf serialized Object in a file generated by a Python process. I now need to deserialize this in Scala.
I dont see scala docs in official google protobuf documentation. Any references? How should i go about it.
I started looking into ScalaPB for this but getting below error. Any suggestions -
plugins.sbt file : `addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.34")
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.10.7"`
Error - [error] (update) sbt.librarymanagement.ResolveException: Error downloading com.thesamet:sbt-protoc;sbtVersion=1.0;scalaVersion=2.12:0.99.34 [error] Not found [error] Not found [error] not found: C:\Users\USER\.ivy2\local\com.thesamet\sbt-protoc\scala_2.12\sbt_1.0\0.99.34\ivys\ivy.xml [error] not found: https://repo1.maven.org/maven2/com/thesamet/sbt-protoc_2.12_1.0/0.99.34/sbt-protoc-0.99.34.pom [error] (ssExtractDependencies) sbt.librarymanagement.ResolveException: Error downloading com.thesamet:sbt-protoc;sbtVersion=1.0;scalaVersion=2.12:0.99.34 [error] Not found [error] Not found [error] not found: C:\Users\USER\.ivy2\local\com.thesamet\sbt-protoc\scala_2.12\sbt_1.0\0.99.34\ivys\ivy.xml [error] not found: https://repo1.maven.org/maven2/com/thesamet/sbt-protoc_2.12_1.0/0.99.34/sbt-protoc-0.99.34.pom [error] Total time: 8 s, completed Jul 23, 2020, 6:41:59 PM [info] shutting down sbt server
You need to have access to proto files that describe message schemas of objects that are serialised in the python process. The files must be shared between projects and it is mandatory information defining the contract.
You can then use ScalaPB to generate corresponding case classes. These classes are autogenerated by the sbt plugin and they provide helper methods that can be used for deserialisation. Check methods parseFrom provided in companion objects of generated Message classes

My First Akka project in IntelliJ from scratch. Compile dependency error.

Every now and then I start things from scratch to make sure I know what all the intricate details of setting up a project are. I have a simple app like the following but I get some dependency issues that don't seem to point me anywhere. I'm using scala verions 2.11.
My SBT:
name := "Helios"
version := "1.0"
scalaVersion := "2.11.8"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies ++= Seq(
"com.typesafe.akka" % "akka-actor" % "2.0.2",
"com.typesafe.akka" % "akka-slf4j" % "2.0.5")
My Sample Class
import com.echostar.ese.helios.core.Asset
import akka.actor._
class NSPSG extends Actor {
def receive = {
case a: Asset => {
println(s"NSPSG Received asset: ${a}")
}
case _ => println("Unexpected message received")
}
}
(Asset class is just a case class with id and title in it.)
Error Message:
C:\PROJECTS\active\Helios>sbt compile
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading global plugins from C:\Users\dana.murad\.sbt\0.13\plugins
[info] Loading project definition from C:\PROJECTS\active\Helios\project
[info] Set current project to Helios (in build file:/C:/PROJECTS/active/Helios/)
[info] Updating {file:/C:/PROJECTS/active/Helios/}helios...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 3 Scala sources to C:\PROJECTS\active\Helios\target\scala-2.11\classes...
[error] missing or invalid dependency detected while loading class file 'package.class'.
[error] Could not access type ScalaObject in package scala,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'package.class' was compiled against an incompatible version of scala.
[error] missing or invalid dependency detected while loading class file 'Actor.class'.
[error] Could not access type ScalaObject in package scala,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'Actor.class' was compiled against an incompatible version of scala.
[error] C:\PROJECTS\active\Helios\src\main\scala\com\echostar\ese\helios\workers\NSPSG.scala:9: illegal inheritance;
[error] self-type com.echostar.ese.helios.workers.NSPSG does not conform to akka.actor.Actor's selftype akka.actor.Actor
[error] class NSPSG extends Actor {
[error] ^
[error] three errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 3 s, completed Apr 4, 2016 9:19:45 AM
My main App is just a println for now. It's not even calling this actor.
Am I using the wrong version of akka with scala 2.11? -Ylog-classpath didn't help
Don't know what fixed it but here's a list of things I did and the project compiles now.
Changed akka dependency line to this (added double percent and changed version back to 2.4)
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.4.0"
)
Removed my Run configuration and added it back again. ( I think the path to main showed as red (invalid) so redoing it helped resolve it. I changed my package name and I don't think intelliJ picked up the rename well in build-conf)
Started another test project from IntelliJ menu (Akka Main in Scala) and that took a bit to download all dependencies. So maybe my project needed those and wasn't download them?
Removed commented out lines (got rid of a semi-colon). I don't think this did anything but full disclosure, technically I did touch the code even though my actor definition is exactly the same.

Bad Symbolic reference to reactivemongo.api.collections.GenericHandlers encountered in class file 'JSONGenericHandlers.class'

I'm having my apis in play 2.3 with reactive mongo. Recently, i tried to cleaned the project and during the process, some things got updated. Later, when i tried to run or compile that, i'm getting these errors. Apart from clean, i didn't do anything. Kindly help me.
[info] Compiling 48 Scala sources and 1 Java source to /home/Ruthvick/zcapi/zceapi /target /scala-2.11/classes...
[error] bad symbolic reference to reactivemongo.api.collections.GenericHandlers encountered in class file 'JSONGenericHandlers.class'.
[error] Cannot access type GenericHandlers in package reactivemongo.api.collections. The current classpath may be
[error] missing a definition for reactivemongo.api.collections.GenericHandlers, or JSONGenericHandlers.class may have been compiled against a version that's
[error] incompatible with the one found on the current classpath.
[error] /home/Ruthvick/zcapi/zceapi/app/controllers/Application.scala:28: type arguments [play.modules.reactivemongo.json.collection.JSONCollection] do not conform to method collection's type parameter bounds [C <: reactivemongo.api.Collection]
[error] def collection: JSONCollection = db.collection[JSONCollection]("shoppage")
[error] ^
[error] /home/Ruthvick/zcapi/zceapi/app/controllers/Application.scala:47: could not find implicit value for parameter writer: GenericCollection.this.pack.Writer[play.api.libs.json.JsObject]
[error] collection.insert(result).map { lastError =>
[error] ^
[error] 60 errors found
[error] (compile:compile) Compilation failed
[error] application -
Thanks,
Your version of Play is not compatible with the newest Snapshot of Play Reactive Mongo. You could just use Version 0.10.5.
Add this to your Library Dependencies
"org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka23"

Class Resolving in one namespace, but not the other

When running play compile, I get a compile-time error.
[error] test.scala:14: object BOMInputStream is not a member of package org.ap
ache.commons.io.input
[error] import org.apache.commons.io.input.BOMInputStream
[error] ^
[error] test.scala:80: not found: type BOMInputStream
[error] val bomIn = new BOMInputStream(fileInpStream, false)
[error] ^
[error] two errors found
However, I successfully ran a scalatest test using the BOMInputStream in the same play project within the /test directory.
When I comment out the offending lines in the above compile-time error, the test succeeds.
Note that I've updated my /project/Build.scala appropriately:
"org.apache.commons" % "commons-io" % "1.3.2"
After deleting a JAR, which contained the BOMInputStream class, from my PLAY-PROJECT/lib/ directory, I was able to compile.

Scala not working with heroku example

I'm following a tutorial to create a scala web app with Heroku here: https://devcenter.heroku.com/articles/scala
I've copied there example exactly, but when I run
sbt clean compile stage
It fails to compile because of these errors:
[error] /home/ajcrites/dev/dyl/src/main/scala/Web.scala:1: object jboss is not a member of package org
[error] import org.jboss.netty.handler.codec.http.{HttpRequest, HttpResponse}
[error] ^
[error] /home/ajcrites/dev/dyl/src/main/scala/Web.scala:2: object twitter is not a member of package com
[error] import com.twitter.finagle.builder.ServerBuilder
[error] ^
[error] /home/ajcrites/dev/dyl/src/main/scala/Web.scala:3: object twitter is not a member of package com
[error] import com.twitter.finagle.http.{Http, Response}
[error] ^
[error] /home/ajcrites/dev/dyl/src/main/scala/Web.scala:4: object twitter is not a member of package com
[error] import com.twitter.finagle.Service
[error] ^
[error] /home/ajcrites/dev/dyl/src/main/scala/Web.scala:5: object twitter is not a member of package com
[error] import com.twitter.util.Future
[error] ^
[error] 5 errors found
Basically, I think it has to do with finagle not being available or not in the packages I have or something. However, I have no idea how to install finagle and there are neither instructions in the tutorial above nor at https://github.com/twitter/finagle
What can I do to get this to compile?
If will depend on the version of Scala and Finagle you want to use, but to add Finagle to the project, just add the following to build.sbt
libraryDependencies += "com.twitter" % "finagle-core_2.9.1" % "1.11.0" exclude("org.apache.thrift", "libthrift")
libraryDependencies += "com.twitter" % "finagle-http_2.9.1" % "1.11.0"
libraryDependencies += "com.twitter" % "finagle-serversets_2.9.1" % "1.11.0" excludeAll(
ExclusionRule(organization = "com.sun.jdmk"),
ExclusionRule(organization = "com.sun.jmx"),
ExclusionRule(organization = "javax.jms")
)
This example is about 3 months old, so I'm sure you can get a newer version of Finagle.
I tried the code and it worked for me. Perhaps see if the source on GitHub works: https://github.com/heroku/devcenter-scala