#!/usr/bin/perl use strict; use warnings; #use Test::More tests => 10; use Test::More qw(no_plan); use Test::Exception; use src::bo::Duck; use src::bo::Rubber; use src::bo::Whistle; use src::bo::behaviour::fly::CanFly; use src::bo::behaviour::fly::CannotFly; use src::bo::behaviour::quack::CanQuack; use src::bo::behaviour::quack::CannotQuack; my $duck = src::bo::Duck->new( ); # a quick check if it's a src::bo::Duck object is ( ref ($duck), "src::bo::Duck", "A duck object" ); # setFlyBehaviour is public so should be callable lives_ok { $duck->setFlyBehaviour( src::bo::behaviour::fly::CannotFly->new() ) } "setFlyBehaviour is public"; # impossible to modify FLYBEHAVIOUR as it is protected throws_ok { $duck->("FLYBEHAVIOUR", src::bo::behaviour::fly::CannotFly->new() ) } qr/FLYBEHAVIOUR is protected/, "FLYBEHAVIOUR is protected"; my $rubber = src::bo::Rubber->new(); # a quick check if it's a src::bo::Rubber object is ( ref ($rubber), "src::bo::Rubber", "A rubber duck object" ); # a rubber duck cannot fly is ( $rubber->doFly(), "cannot fly", "the rubber duck cannot fly" ); # a rubber duck sqeeks is ( $rubber->doQuack(), "can sqeek", "the rubber duck sqeeks" ); my $whistle = src::bo::Whistle->new(); # a quick check if it's a src::bo::Whistle object is ( ref ($whistle), "src::bo::Whistle", "A whistle object" ); # a whistle duck cannot fly is ( $whistle->doFly(), "cannot fly", "the whistle doesn't fly" ); # a whistle cannot quack is ( $whistle->doQuack(), "cannot quack", "the whistle doesn't quack" ); # setQuackBehaviour is public so should be callable lives_ok { $whistle->setQuackBehaviour( src::bo::behaviour::quack::CanQuack->new() ) } "setQuackBehaviour is public"; # impossible to modify QUACKBEHAVIOUR as it is protected throws_ok { $whistle->("QUACKBEHAVIOUR", src::bo::behaviour::quack::CanQuack->new() ) } qr/QUACKBEHAVIOUR is protected/, "QUACKBEHAVIOUR is protected"; # a whistle does quack now because we use a strategy pattern is ( $whistle->doQuack(), "can quack", "the whistle does quack" ); $rubber->setColor("red"); is ( $rubber->getColor(), "red", "rubber is a red color" );