#!/usr/bin/perl use strict; use warnings; use Math::BigInt; use Test::More tests => 15; use Test::Exception; # We need the Rekening and Actief classes use src::bo::Rekening; # a quick test to see if rekening works my $rekening = Rekening->new("rekeningnaam"); is( ref $rekening, "Rekening", "A rekening object" ); is( $rekening->getName(), "rekeningnaam", "It's rekeningnaam" ); my $zero = Math::BigInt->new(0); is( $rekening->getCreditAmount(), $zero, "kas has 0 credit" ); is( ref $rekening->getCreditAmount(), "Math::BigInt", "getCreditAmount() returns a BigInt" ); is( $rekening->getDebetAmount(), $zero, "kas has 0 debet" ); is( ref $rekening->getDebetAmount(), "Math::BigInt", "getDebetAmount() returns a BigInt" ); # we test a rekening without a name my $rekening2 = Rekening->new(); is( ref $rekening2, "Rekening", "A rekening object" ); is( $rekening2->getName(), undef, "It's undef" ); # we test if we can call addToAccount directly throws_ok { $rekening->addToAccount() } qr/Rekening is a base class/, "addToAccount is protected"; # we test if we can call subtractFromAccount directly throws_ok { $rekening->subtractFromAccount() } qr/Rekening is a base class/, "subtractFromAccount is protected"; # we test if we can call balance directly throws_ok { $rekening->balance() } qr/Rekening is a base class/, "balance is protected"; # we test if we can call setCreditAmount directly throws_ok { $rekening->setCreditAmount(0) } qr/setCreditAmount is protected/, "setCreditAmount is protected"; # we test if we can call setDebetAmount directly throws_ok { $rekening->setDebetAmount(0) } qr/setDebetAmount is protected/, "setDebetAmount is protected"; # magic, we test the setCredit protected sub my $setCredit; my $setDebet; { package Sub::Rekening; our @ISA = 'Rekening'; eval { $rekening->setCreditAmount($two); $rekening->setDebetAmount($one); $setCredit = $rekening->getCreditAmount(); $setDebet = $rekening->getDebetAmount(); }; } is( $setCredit, $two, "setCreditAmount returns 2" ); is( $setDebet, $one, "setDebetAmount returns 1" );