From 31054d667bfec0227e0973b35b6a5137c56ffcd1 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Sat, 24 Nov 2012 16:32:35 +0000 Subject: The argument to our class factories must be a non-nil string. --- lib/custodian/alertfactory.rb | 3 +++ lib/custodian/testfactory.rb | 4 ++++ t/test-custodian-alertfactory.rb | 19 +++++++++++++++++++ t/test-custodian-testfactory.rb | 17 +++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/lib/custodian/alertfactory.rb b/lib/custodian/alertfactory.rb index e176f6d..3df6233 100644 --- a/lib/custodian/alertfactory.rb +++ b/lib/custodian/alertfactory.rb @@ -31,6 +31,9 @@ module Custodian # def self.create( alert_type, obj ) + raise ArgumentError, "The type of alerter to create cannot be nil" if ( alert_type.nil? ) + raise ArgumentError, "The type of alerter to create must be a string" unless ( alert_type.kind_of? String ) + c = @@subclasses[alert_type] if c c.new( obj ) diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb index f5e342d..ccfc89e 100644 --- a/lib/custodian/testfactory.rb +++ b/lib/custodian/testfactory.rb @@ -31,6 +31,10 @@ module Custodian # def self.create( line ) + + raise ArgumentError, "The type of test to create cannot be nil" if ( line.nil? ) + raise ArgumentError, "The type of test to create must be a string" unless ( line.kind_of? String ) + # # If this is an obvious protocol test. # diff --git a/t/test-custodian-alertfactory.rb b/t/test-custodian-alertfactory.rb index ede6aa7..4f2fb8d 100755 --- a/t/test-custodian-alertfactory.rb +++ b/t/test-custodian-alertfactory.rb @@ -51,6 +51,25 @@ class TestAlertFactory < Test::Unit::TestCase assert( obj.respond_to? "raise" ) assert( obj.respond_to? "clear" ) end + + + # + # Creating an alert we don't know about is an error + # + assert_raise ArgumentError do + obj = Custodian::AlertFactory.create( "not found", nil ) + end + + # + # A string is mandatory + # + assert_raise ArgumentError do + obj = Custodian::AlertFactory.create( nil, nil ) + end + assert_raise ArgumentError do + obj = Custodian::AlertFactory.create( Array.new, nil ) + end + end end diff --git a/t/test-custodian-testfactory.rb b/t/test-custodian-testfactory.rb index 65abc5b..b210ef9 100755 --- a/t/test-custodian-testfactory.rb +++ b/t/test-custodian-testfactory.rb @@ -22,6 +22,23 @@ class TestTestFactory < Test::Unit::TestCase end + # + # Test bogus creation + # + def test_init + + assert_raise ArgumentError do + obj = Custodian::TestFactory.create( nil, nil ) + end + + assert_raise ArgumentError do + obj = Custodian::TestFactory.create( Array.new, nil ) + end + + + end + + # # Test the FTP-test may be created # -- cgit v1.2.1