Skip to content

Commit

Permalink
Add test case covering exceptions thrown from JFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei committed Apr 18, 2024
1 parent 8d81c36 commit df65224
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/programs/unit_tests/JFactoryTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<JEvent>();
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<JEvent>();
JFactoryTestExceptingInInitFactory fac;
REQUIRE(fac.GetStatus() == JFactory::Status::Uninitialized);
REQUIRE_THROWS(fac.CreateAndGetData(event));

REQUIRE(fac.GetStatus() == JFactory::Status::Uninitialized);
REQUIRE_THROWS(fac.CreateAndGetData(event));
}
}

16 changes: 16 additions & 0 deletions src/programs/unit_tests/JFactoryTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ struct JFactoryTestDummyFactory : public JFactoryT<JFactoryTestDummyObject> {
}
};

struct JFactoryTestExceptingFactory : public JFactoryT<JFactoryTestDummyObject> {

void Process(const std::shared_ptr<const JEvent>&) override {
throw JException("This was never going to work!");
}
};

struct JFactoryTestExceptingInInitFactory : public JFactoryT<JFactoryTestDummyObject> {

void Init() override {
throw JException("This was never going to initialize even");
}
void Process(const std::shared_ptr<const JEvent>&) override {
}
};


struct JFactoryTestDummySource: public JEventSource {

Expand Down

0 comments on commit df65224

Please sign in to comment.