Add coverage tests, convert croaks to exceptions.

This commit is contained in:
Colin Kuskie 2008-03-05 23:34:53 +00:00
parent cd55ff1a9e
commit d27ac7a629
4 changed files with 55 additions and 10 deletions

View file

@ -2,7 +2,6 @@ package WebGUI::Shop::Ship;
use strict;
use Carp qw(croak);
use WebGUI::International;
use WebGUI::Shop::ShipDriver;
use WebGUI::Pluggable;
@ -104,8 +103,9 @@ A WebGUI::Session object. A WebGUI::Error::InvalidParam exception will be throw
sub getOptions {
my $class = shift;
my $session = shift;
croak "Definition requires a session object"
WebGUI::Error::InvalidParam->throw(error => q{Must provide a session variable})
unless ref $session eq 'WebGUI::Session';
return;
}
#-------------------------------------------------------------------

View file

@ -273,8 +273,11 @@ sub new {
my $properties = $session->db->quickHashRef('select * from shipper where shipperId=?',[$shipperId]);
WebGUI::Error::ObjectNotFound->throw(error => q{shipperId not found in db}, id => $shipperId)
unless scalar keys %{ $properties };
croak "Somehow, the options property of this object, $shipperId, got broken in the db"
unless exists $properties->{options} and $properties->{options};
##This check is just to guardband the from_json call below.
WebGUI::Error::InvalidParam->throw(
error => qq{Options property for $shipperId was broken in the db},
param => $properties->{options},
) unless $properties->{options}; ##Note, existence is controlled by the columns in the db
my $options = from_json($properties->{options});
my $self = WebGUI::Shop::ShipDriver->_buildObj($session, $class, $shipperId, $options);
return $self;