Migrating testcase to ScalaTest

This commit is contained in:
Naoki Takezoe
2016-02-04 00:40:58 +09:00
parent 0067cbce6f
commit 911754e1dc
2 changed files with 34 additions and 39 deletions

View File

@@ -1,26 +1,25 @@
package gitbucket.core.model package gitbucket.core.model
import gitbucket.core.model.CommitState._ import gitbucket.core.model.CommitState._
import org.scalatest.FunSpec
import org.specs2.mutable.Specification
class CommitStateSpec extends Specification { class CommitStateSpec extends FunSpec {
"CommitState" should { describe("CommitState") {
"combine empty must eq PENDING" in { it("should combine empty must eq PENDING") {
combine(Set()) must_== PENDING assert(combine(Set()) == PENDING)
} }
"combine includes ERROR must eq FAILURE" in { it("should combine includes ERROR must eq FAILURE") {
combine(Set(ERROR, SUCCESS, PENDING)) must_== FAILURE assert(combine(Set(ERROR, SUCCESS, PENDING)) == FAILURE)
} }
"combine includes FAILURE must eq peinding" in { it("should combine includes FAILURE must eq peinding") {
combine(Set(FAILURE, SUCCESS, PENDING)) must_== FAILURE assert(combine(Set(FAILURE, SUCCESS, PENDING)) == FAILURE)
} }
"combine includes PENDING must eq peinding" in { it("should combine includes PENDING must eq peinding") {
combine(Set(PENDING, SUCCESS)) must_== PENDING assert(combine(Set(PENDING, SUCCESS)) == PENDING)
} }
"combine only SUCCESS must eq SUCCESS" in { it("should combine only SUCCESS must eq SUCCESS") {
combine(Set(SUCCESS)) must_== SUCCESS assert(combine(Set(SUCCESS)) == SUCCESS)
} }
} }
} }

View File

@@ -1,39 +1,35 @@
package gitbucket.core.ssh package gitbucket.core.ssh
import org.specs2.mutable._
import org.specs2.mock.Mockito
import org.apache.sshd.server.command.UnknownCommand import org.apache.sshd.server.command.UnknownCommand
import javax.servlet.ServletContext import org.scalatest.FunSpec
class GitCommandFactorySpec extends Specification with Mockito { class GitCommandFactorySpec extends FunSpec {
val factory = new GitCommandFactory("http://localhost:8080") val factory = new GitCommandFactory("http://localhost:8080")
"createCommand" should { describe("createCommand") {
"returns GitReceivePack when command is git-receive-pack" in { it("should return GitReceivePack when command is git-receive-pack"){
factory.createCommand("git-receive-pack '/owner/repo.git'").isInstanceOf[DefaultGitReceivePack] must beTrue assert(factory.createCommand("git-receive-pack '/owner/repo.git'").isInstanceOf[DefaultGitReceivePack] == true)
factory.createCommand("git-receive-pack '/owner/repo.wiki.git'").isInstanceOf[DefaultGitReceivePack] must beTrue assert(factory.createCommand("git-receive-pack '/owner/repo.wiki.git'").isInstanceOf[DefaultGitReceivePack] == true)
} }
"returns GitUploadPack when command is git-upload-pack" in { it("should return GitUploadPack when command is git-upload-pack"){
factory.createCommand("git-upload-pack '/owner/repo.git'").isInstanceOf[DefaultGitUploadPack] must beTrue assert(factory.createCommand("git-upload-pack '/owner/repo.git'").isInstanceOf[DefaultGitUploadPack] == true)
factory.createCommand("git-upload-pack '/owner/repo.wiki.git'").isInstanceOf[DefaultGitUploadPack] must beTrue assert(factory.createCommand("git-upload-pack '/owner/repo.wiki.git'").isInstanceOf[DefaultGitUploadPack] == true)
} }
"returns UnknownCommand when command is not git-(upload|receive)-pack" in { it("should return UnknownCommand when command is not git-(upload|receive)-pack"){
factory.createCommand("git- '/owner/repo.git'").isInstanceOf[UnknownCommand] must beTrue assert(factory.createCommand("git- '/owner/repo.git'").isInstanceOf[UnknownCommand] == true)
factory.createCommand("git-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] must beTrue assert(factory.createCommand("git-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] == true)
factory.createCommand("git-a-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] must beTrue assert(factory.createCommand("git-a-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] == true)
factory.createCommand("git-up-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] must beTrue assert(factory.createCommand("git-up-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] == true)
factory.createCommand("\ngit-upload-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] must beTrue assert(factory.createCommand("\ngit-upload-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] == true)
} }
"returns UnknownCommand when git command has no valid arguments" in { it("should return UnknownCommand when git command has no valid arguments"){
// must be: git-upload-pack '/owner/repository_name.git' // must be: git-upload-pack '/owner/repository_name.git'
factory.createCommand("git-upload-pack").isInstanceOf[UnknownCommand] must beTrue assert(factory.createCommand("git-upload-pack").isInstanceOf[UnknownCommand] == true)
factory.createCommand("git-upload-pack /owner/repo.git").isInstanceOf[UnknownCommand] must beTrue assert(factory.createCommand("git-upload-pack /owner/repo.git").isInstanceOf[UnknownCommand] == true)
factory.createCommand("git-upload-pack 'owner/repo.git'").isInstanceOf[UnknownCommand] must beTrue assert(factory.createCommand("git-upload-pack 'owner/repo.git'").isInstanceOf[UnknownCommand] == true)
factory.createCommand("git-upload-pack '/ownerrepo.git'").isInstanceOf[UnknownCommand] must beTrue assert(factory.createCommand("git-upload-pack '/ownerrepo.git'").isInstanceOf[UnknownCommand] == true)
factory.createCommand("git-upload-pack '/owner/repo.wiki'").isInstanceOf[UnknownCommand] must beTrue assert(factory.createCommand("git-upload-pack '/owner/repo.wiki'").isInstanceOf[UnknownCommand] == true)
} }
} }