Chapter 11
[ 305 ]
In the setup method, we create an account object with a BASIC plan. We set up four
different media objects, and load the reward rules. We can assert that the outcome
was as expected. For instance, in the first test we consume a Disney video and assert
that the bonus points have been added. For completeness, we then consume a non-
Disney video and see that no bonus points have been added.
def account
def up
def terminator
def halo3
def halo1
def bbPlus
def setup() {
account = new Account(plan:"BASIC", points:120, spend:0.0)
up = new Media(title:"UP", type:"VIDEO", newRelease:true,
price:3.99, points:40, daysAccess:1,
publisher:"Disney")
terminator = new Media(title:"Terminator", type:"VIDEO",
newRelease:false, price:2.99, points:30,
daysAccess:1, publisher:"Fox")
halo3 = new Media(title:"Halo III", type:"GAME",
newRelease:true, price:2.99, points:30,
daysAccess:3, publisher:"Microsoft")
halo1 = new Media(title:"Halo", type:"GAME",
newRelease:false, price:1.99, points:20,
daysAccess:3,publisher:"Microsoft")
bbPlus = new BroadbandPlus()
RewardService.loadRewardRules()
}
def "Disney Reward programme is applied"() {
expect:
bbPlus.canConsume(account, up)
account.points == 120
when:
def expected = account.points - up.points + up.points / 4
bbPlus.consume(account, up)