ScalaMock won't mock my TextMessage

scala mock singleton object
scalamock maven
scala mock object
scalamock overloaded method
scala mock trait
scalamock vs mockito
scalamock multiple parameters
scalamock spy

I am using ScalaMock3 and I am trying to create a mock of a javax.jms.TextMessage within my ScalaTest spec.

import javax.jms.TextMessage
import org.scalamock.scalatest.MockFactory
import org.scalatest.{Matchers, WordSpecLike}

class MySpec extends WordSpecLike
  with Matchers
  with MockFactory {

  "MySpec" should {
    "create the mock I want!" in {

      val msg = mock[TextMessage]
      msg.getText _ expects() returning "my_text"

      msg.getText shouldBe "my_text"

However, when I try to compile, I get the following:

[error] /my/path/MySpec.scala:14: could not find implicit value for evidence parameter of type org.scalamock.util.Defaultable[java.util.Enumeration]  
[error] val msg = mock[TextMessage] 

Looking online, I found this (unresolved) issue, but I was hoping someone could suggest a work-around at least...


Basically this happens because of the API differences between Java 1.4 and >= 1.5 versions.

TextMessage uses the Java 1.4 non-generic type java.util.Enumeration (return type from getPropertyNames inherited from javax.jms.Message), whereas in newer JVMs java.util.Enumeration<E> is a generic class with a type parameter.

When ScalaMock tries to create a mocked instance of this interface, it fails there:

Main.scala:46: trait Enumeration takes type parameters

I don't think there's much you can do unfortunately.

Quick Start, type PlayerId = Int case class Player(id: PlayerId, nickname: String, country: Country) case class MatchResult(winner: PlayerId, loser: PlayerId). There is also the� ScalaMock won't mock my TextMessage. Ask Question Asked 3 years, 8 months ago. Active 9 months ago. Viewed 369 times 0. I am using ScalaMock3 and I am

There is a fixed issue for ScalaMock:

Add this to your code:

implicit val d = new Defaultable[java.util.Enumeration[_]] {
  override val default = null

ScalaMock won't mock my TextMessage, Basically this happens because of the API differences between Java 1.4 and >= 1.5 versions. TextMessage uses the Java 1.4 non-generic type� sbt started warning about a possible conflict with org.scala:2.10.0 unless I moved the ScalaMock dependency out of test scope IntelliJ's syntax highlighting became thoroughly confused (I'm slightly behind here, I'll try bumping to latest versions of the IDE and scala plugin to see if that helps)

While it's not an optimal solution, embedding the offending class in a wrapper class allows for mocking the behavior within your test suite.

class TextMessageWrapper {
  lazy val textMessage: TextMessage = ???

  def getMessage() = textMessage.getMessage()

You can then pass wrapper.textMessage wherever an instance of TextMessage is required

ScalaMock 3.0 problems with polymorphic types � Issue #24 , class MockingTest extends FunSuite with MockFactory { test("mock[Connection] won't compile") { val conn = mock[java.sql.Connection]� one won’t make mistake in the middle levels; using scalamock is hard because Freestyle protects handlers methods; Other problems Doobie trap! Freestyle provides DoobieM, with def transact(c: ConnectionIO)method, for support of Doobie database access. Helper for transforming Transactor to DoobieM.Handler is in place. Wiring Doobie in is easy

Have you tried this?

implicit object DefaultableEnumeration extends Defaultable[java.util.Enumeration[Object]] {
    val default = new java.util.Enumeration[Object] {
        override def hasMoreElements: Boolean = false
        override def nextElement: Object = throw new NoSuchElementException("no elements")

I did something similar when I got this error with java.util.List<T> and the compiler stopped complaining after this.

mocking default arguments � Issue #43 � paulbutcher/ScalaMock , But I need to write a couple more tests to check it won't break anything. This week I'm going to release ScalaMock-3.2.1 with fix for #85 and two� // this won't compile trait Animal(name: String) So, use an abstract class whenever a base behavior must have constructor parameters: abstract class Animal(name: String) Regarding the second reason, if you’re writing code that needs to be accessed from Java, you’ll find that Scala traits with implemented methods can’t be called from Java

ScalaMock won't mock my TextMessage - scala - html, TextMessage import org.scalamock.scalatest.MockFactory import org.scalatest.{ Matchers, WordSpecLike} class MySpec extends WordSpecLike with Matchers� In IDEA 2017.1.2, I have the following failure: When using ScalaMock, given, in part, from public interface Config extends ConfigMergeable { String getString(String

JMock to Scalamock Cheat Sheet, An abbreviated set of JMock examples with their Scalamock Using subtypes like this in JMock is a bit of a smell as a test won't fail if a� This post describes ScalaMock 3, which supports Scala 2.10 only. For ScalaMock 2, which supports earlier Scala versions, go here. This post describes how to setup a project that uses ScalaMock in conjunction with ScalaTest and sbt. The sample code described in this article is available on GitHub.

Scalamock, It looks like the latest ScalaTest version that ScalaMock is built for is 2.0.M5b We submitted a pull request for ScalaMock already, so hopefully we won't have to � ScalaMock 3 supports two types of mock, proxy mocks and macro mocks. Proxy mocks are not type checked and have a slightly less convenient syntax than macro mocks, but they work with any trait and are fully supported.