diff --git a/src/programs/unit_tests/JFactoryTests.cc b/src/programs/unit_tests/JFactoryTests.cc index 6cb6cba9a..159ee8ae7 100644 --- a/src/programs/unit_tests/JFactoryTests.cc +++ b/src/programs/unit_tests/JFactoryTests.cc @@ -197,5 +197,27 @@ TEST_CASE("JFactoryTests") { REQUIRE((*it)->data == 49); REQUIRE(sut.GetNumObjects() == 1); } + + SECTION("Exception in JFactory::Process") { + LOG << "JFactoryTests: Exception in JFactory::Process" << LOG_END; + auto event = std::make_shared(); + JFactoryTestExceptingFactory fac; + REQUIRE(fac.GetStatus() == JFactory::Status::Uninitialized); + REQUIRE_THROWS(fac.CreateAndGetData(event)); + + REQUIRE(fac.GetStatus() == JFactory::Status::Unprocessed); + REQUIRE_THROWS(fac.CreateAndGetData(event)); + } + + SECTION("Exception in JFactory::Init") { + LOG << "JFactoryTests: Exception in JFactory::Init" << LOG_END; + auto event = std::make_shared(); + JFactoryTestExceptingInInitFactory fac; + REQUIRE(fac.GetStatus() == JFactory::Status::Uninitialized); + REQUIRE_THROWS(fac.CreateAndGetData(event)); + + REQUIRE(fac.GetStatus() == JFactory::Status::Uninitialized); + REQUIRE_THROWS(fac.CreateAndGetData(event)); + } } diff --git a/src/programs/unit_tests/JFactoryTests.h b/src/programs/unit_tests/JFactoryTests.h index 6bc54a201..fdb9362c5 100644 --- a/src/programs/unit_tests/JFactoryTests.h +++ b/src/programs/unit_tests/JFactoryTests.h @@ -50,6 +50,22 @@ struct JFactoryTestDummyFactory : public JFactoryT { } }; +struct JFactoryTestExceptingFactory : public JFactoryT { + + void Process(const std::shared_ptr&) override { + throw JException("This was never going to work!"); + } +}; + +struct JFactoryTestExceptingInInitFactory : public JFactoryT { + + void Init() override { + throw JException("This was never going to initialize even"); + } + void Process(const std::shared_ptr&) override { + } +}; + struct JFactoryTestDummySource: public JEventSource {