Test Builder Source
Unit tests for the Builder Pattern implementation.
This file contains unit tests for the Builder Pattern, ensuring that the ConcreteBuilder and Director classes work as expected to construct a Product.
Functions
-
TEST(BuilderPatternTest, FullProductConstruction)
Test full product construction using ConcreteBuilder and Director.
Verifies that the
Directororchestrates theConcreteBuildercorrectly to construct a product with all expected parts (PartAandPartB) built as specified.- Test:
Steps:
Create a
ConcreteBuilderand pass it to aDirector.Invoke
Director::construct()to build the product.Retrieve the product from the
Directorand verify its string representation.
-
TEST(BuilderPatternTest, PartialProductConstruction)
Test partial product construction directly through the ConcreteBuilder.
Verifies that the
ConcreteBuildercan construct a product incrementally without the involvement of theDirector.- Test:
Steps:
Create a
ConcreteBuilder.Call
ConcreteBuilder::buildPartA()but skipbuildPartB().Retrieve the product and verify its string representation reflects only Part A.
-
TEST(BuilderPatternTest, BuilderReuse)
Test reusing a builder for multiple products.
Ensures that the
ConcreteBuildercan be reused to construct multiple products by resetting or reinitializing its internal state.- Test:
Steps:
Create a
ConcreteBuilderand use it with aDirectorto construct a product.Retrieve the product and verify its details.
Reuse the same builder to construct another product and verify its details.
-
TEST(BuilderPatternTest, DirectBuilderUsage)
Test constructing a product without using the Director.
Ensures that the
ConcreteBuildercan independently construct a product without orchestration from theDirector.- Test:
Steps:
Create a
ConcreteBuilder.Call both
buildPartA()andbuildPartB()directly on the builder.Retrieve the product and verify its string representation.