Message.scala - メッセージ コンパニオンクラス
package tanuneko.ui2 class Message(val msg:String) { def this() = this(msg = "") override def toString():String = { s"msg:${msg}" } def show(): Unit = { println(msg) } } object Message { def apply(): Unit = new Message() def apply(msg:String) = new Message(msg) def unapply(res:Message) = Some(res.msg + "dayon") }
MessageTestSpec.scala - メッセージspec2テスト
package tanuneko.test import tanuneko.ui2.Message import org.specs2._ class MessageTestSpec extends mutable.Specification { "Message unapply" should { "return its msg field" in { val resp = Message("nyanchan") var isOk = resp match { case Message(x) if x == "nyanchandayon" => true case _ => false } isOk must beTrue } } }
0 件のコメント:
コメントを投稿