0

I am trying out ScalaMock in my scala application What i have is an RSSReader which reads data from XML using XML.load(<urlString>), like in the code below

class ScalaRssFinancialDataReader 
  ....
  def fetchRSS(url:String) = XML.load(url) 
  ....
}

I am mocking it like this

"fetching global economics mocking XML trait" should "return data" in {

  val xmlFragment = <item><title>foo</title><author>a</author></item>
  val xmlMock = mock[scala.xml.XML]
  val tradingEconomicsUrl = "http://www.tradingeconomics.com/russia/rss"

  (xmlMock.load_).expects(tradingEconomicsUrl).returns(xmlFragment)

  val rssReader = new com.worldcorpservices.rss.reader.ScalaRssFinancialDataReader()

  val res = rssReader.fetchRssData("http://www.tradingeconomics.com/russia/rss", "RUSSIA")

  assert(res.size() == 1)

}

the problem is that i keep on getting exception that 'XML is not part of p ackage scala.xml

What am i doing wrong here? is it possible to mock XML.load method?

kind regards marco

Ende Neu
  • 15,581
  • 5
  • 57
  • 68
user1068378
  • 333
  • 2
  • 12

1 Answers1

0

scala.xml.XML is an object, Mockito cannot mock objects, you may want to check ScalaMock (expecially here) for that. What I usually do is create a test file and use that as test case, you don't really need to mock the method.

Check also this question and this question.

Community
  • 1
  • 1
Ende Neu
  • 15,581
  • 5
  • 57
  • 68