I am trying to write some test code for my java application using Scalatest. I figured, since Scala has so much more readable syntax it would result with more readable test code.
So far, this is what I managed:
package com.xyz
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
import com.xyz.SecurityService
import org.mockito.Mockito._
import org.scalatest.mock.MockitoSugar
import org.mockito.Matchers._
import javax.servlet.jsp.tagext.Tag
class CheckRoleTagSpec extends FlatSpec with ShouldMatchers with MockitoSugar {
behavior of "CheckRole tag"
it should "allow access when neither role nor root defined" in {
val securityServiceMock = mock[SecurityService]
val tag = new CheckRoleTag()
tag.setSecurityService(securityServiceMock)
tag.setGroup("group")
tag.setPortal("portal")
tag.setRoot(false)
tag.setRole(null)
tag.doStartTag should be(Tag.SKIP_BODY)
}
}
I am quite dissapointed with this code. It’s practically the same thing I would need to write in Java. Please help me make it more scala-like and functional.
The code below creates new anonymous class, but
doStartTagreturns result as expected: