mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-03-02 19:50:21 +00:00
added and expanded tests in hopes of increasing code coverage score
added tests for AvatarService and PacketCodingActor; especially PCA tests
This commit is contained in:
parent
0e5afe6cfd
commit
3aee0ab4e8
69 changed files with 4534 additions and 3037 deletions
|
|
@ -281,5 +281,43 @@ class NumberPoolHubTest extends Specification {
|
|||
val hub = new NumberPoolHub(src)
|
||||
hub.unregister(4).isFailure mustEqual true
|
||||
}
|
||||
|
||||
"identity an object that is registered to it" in {
|
||||
val hub1 = new NumberPoolHub(new LimitedNumberSource(10))
|
||||
val hub2 = new NumberPoolHub(new LimitedNumberSource(10))
|
||||
val obj1 = new EntityTestClass()
|
||||
val obj2 = new EntityTestClass()
|
||||
hub1.register(obj1)
|
||||
hub2.register(obj2)
|
||||
|
||||
hub1.isRegistered(obj1) mustEqual true
|
||||
hub2.isRegistered(obj2) mustEqual true
|
||||
hub1.isRegistered(obj2) mustEqual false
|
||||
hub2.isRegistered(obj1) mustEqual false
|
||||
}
|
||||
|
||||
"identity a number that is registered to it" in {
|
||||
val src1 = new LimitedNumberSource(5)
|
||||
val hub1 = new NumberPoolHub(src1)
|
||||
val src2 = new LimitedNumberSource(10)
|
||||
src2.Restrict(0)
|
||||
src2.Restrict(1)
|
||||
src2.Restrict(2)
|
||||
src2.Restrict(3)
|
||||
src2.Restrict(4)
|
||||
src2.Restrict(5)
|
||||
val hub2 = new NumberPoolHub(src2)
|
||||
val obj1 = new EntityTestClass()
|
||||
val obj2 = new EntityTestClass()
|
||||
hub1.register(obj1)
|
||||
hub2.register(obj2)
|
||||
val num1 = obj1.GUID.guid
|
||||
val num2 = obj2.GUID.guid
|
||||
|
||||
hub1.isRegistered(num1) mustEqual true
|
||||
hub2.isRegistered(num2) mustEqual true
|
||||
hub1.isRegistered(num2) mustEqual false
|
||||
hub2.isRegistered(num1) mustEqual false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,14 @@ class NumberPoolTest extends Specification {
|
|||
ok
|
||||
}
|
||||
|
||||
"fail to construct 1 (number less than zero)" in {
|
||||
new SimplePool(-1 :: Nil) must throwA[IllegalArgumentException]
|
||||
}
|
||||
|
||||
"fail to construct 2 (duplicate numbers)" in {
|
||||
new SimplePool(1 :: 1 :: Nil) must throwA[IllegalArgumentException]
|
||||
}
|
||||
|
||||
"get a number" in {
|
||||
val obj = new SimplePool((0 to 10).toList)
|
||||
obj.Get() match {
|
||||
|
|
@ -26,6 +34,13 @@ class NumberPoolTest extends Specification {
|
|||
}
|
||||
}
|
||||
|
||||
"used number count is always zero" in {
|
||||
val obj = new SimplePool((0 to 10).toList)
|
||||
obj.Count mustEqual 0
|
||||
obj.Get()
|
||||
obj.Count mustEqual 0
|
||||
}
|
||||
|
||||
"return a number" in {
|
||||
//returning a number for a SimplePool is actually just a way of checking that the number is in the "pool" at all
|
||||
val obj = new SimplePool((0 to 10).toList)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package objects.number
|
|||
|
||||
import net.psforever.objects.guid.AvailabilityPolicy
|
||||
import net.psforever.objects.guid.key.{LoanedKey, SecureKey}
|
||||
import net.psforever.packet.game.PlanetSideGUID
|
||||
import org.specs2.mutable.Specification
|
||||
|
||||
class NumberSourceTest extends Specification {
|
||||
|
|
@ -102,6 +103,17 @@ class NumberSourceTest extends Specification {
|
|||
result2.get.Object mustEqual Some(test)
|
||||
}
|
||||
|
||||
"return a secure key" in {
|
||||
val obj = LimitedNumberSource(25)
|
||||
val test = new TestClass()
|
||||
val result1 : Option[LoanedKey] = obj.Available(5)
|
||||
result1.get.Object = test
|
||||
test.GUID = PlanetSideGUID(5)
|
||||
val result2 : Option[SecureKey] = obj.Get(5)
|
||||
|
||||
obj.Return(result2.get) mustEqual Some(test)
|
||||
}
|
||||
|
||||
"restrict a previously-assigned number" in {
|
||||
val obj = LimitedNumberSource(25)
|
||||
val test = new TestClass()
|
||||
|
|
|
|||
60
common/src/test/scala/objects/number/RegisterTest.scala
Normal file
60
common/src/test/scala/objects/number/RegisterTest.scala
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package objects.number
|
||||
|
||||
import akka.actor.Actor
|
||||
import net.psforever.objects.guid.actor.Register
|
||||
import org.specs2.mutable.Specification
|
||||
|
||||
class RegisterTest extends Specification {
|
||||
val obj = new net.psforever.objects.entity.IdentifiableEntity() {}
|
||||
|
||||
"Register" should {
|
||||
"construct (object)" in {
|
||||
val reg = Register(obj)
|
||||
reg.obj mustEqual obj
|
||||
reg.number mustEqual None
|
||||
reg.name mustEqual None
|
||||
reg.callback mustEqual None
|
||||
}
|
||||
|
||||
"construct (object, callback)" in {
|
||||
val reg = Register(obj, Actor.noSender)
|
||||
reg.obj mustEqual obj
|
||||
reg.number mustEqual None
|
||||
reg.name mustEqual None
|
||||
reg.callback mustEqual Some(Actor.noSender)
|
||||
}
|
||||
|
||||
"construct (object, suggested number)" in {
|
||||
val reg = Register(obj, 5)
|
||||
reg.obj mustEqual obj
|
||||
reg.number mustEqual Some(5)
|
||||
reg.name mustEqual None
|
||||
reg.callback mustEqual None
|
||||
}
|
||||
|
||||
"construct (object, suggested number, callback)" in {
|
||||
val reg = Register(obj, 5, Actor.noSender)
|
||||
reg.obj mustEqual obj
|
||||
reg.number mustEqual Some(5)
|
||||
reg.name mustEqual None
|
||||
reg.callback mustEqual Some(Actor.noSender)
|
||||
}
|
||||
|
||||
"construct (object, pool name)" in {
|
||||
val reg = Register(obj, "pool")
|
||||
reg.obj mustEqual obj
|
||||
reg.number mustEqual None
|
||||
reg.name mustEqual Some("pool")
|
||||
reg.callback mustEqual None
|
||||
}
|
||||
|
||||
"construct (object, pool name, callback)" in {
|
||||
val reg = Register(obj, "pool", Actor.noSender)
|
||||
reg.obj mustEqual obj
|
||||
reg.number mustEqual None
|
||||
reg.name mustEqual Some("pool")
|
||||
reg.callback mustEqual Some(Actor.noSender)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue