11package com .baeldung .templatemethodpatterntest ;
22
3+ import com .baeldung .templatemethodpattern .model .Computer ;
4+ import com .baeldung .templatemethodpattern .model .HighEndComputerBuilder ;
5+ import com .baeldung .templatemethodpattern .model .StandardComputerBuilder ;
36import com .baeldung .templatemethodpattern .model .HighEndComputer ;
47import com .baeldung .templatemethodpattern .model .StandardComputer ;
58import org .junit .Assert ;
69import static org .junit .Assert .assertEquals ;
710import org .junit .BeforeClass ;
811import org .junit .Test ;
12+ import static org .hamcrest .CoreMatchers .instanceOf ;
13+ import static org .junit .Assert .assertThat ;
914
1015public class TemplateMethodPatternTest {
1116
12- private static StandardComputer standardComputer ;
13- private static HighEndComputer highEndComputer ;
14-
17+ private static StandardComputerBuilder standardComputerBuilder ;
18+ private static HighEndComputerBuilder highEndComputerBuilder ;
19+
1520 @ BeforeClass
16- public static void setUpStandardComputerInstance () {
17- standardComputer = new StandardComputer ();
21+ public static void setUpStandardComputerBuilderInstance () {
22+ standardComputerBuilder = new StandardComputerBuilder ();
1823 }
19-
24+
2025 @ BeforeClass
21- public static void setUpHighEndComputerInstance () {
22- highEndComputer = new HighEndComputer ();
26+ public static void setUpHighEndComputerBuilderInstance () {
27+ highEndComputerBuilder = new HighEndComputerBuilder ();
2328 }
2429
2530 @ Test
@@ -30,45 +35,55 @@ public void givenStandardMotherBoard_whenAddingMotherBoard_thenEqualAssertion()
3035
3136 @ Test
3237 public void givenStandardMotheroboard_whenSetup_thenTwoEqualAssertions () {
33- standardComputer .setupMotherboard ();
34- assertEquals ("Screwing the standard motherboard to the case." , standardComputer .getMotherboardSetupStatus ().get (0 ));
35- assertEquals ("Plugin in the power supply connectors." , standardComputer .getMotherboardSetupStatus ().get (1 ));
38+ standardComputerBuilder .setupMotherboard ();
39+ assertEquals ("Screwing the standard motherboard to the case." , standardComputerBuilder .getMotherboardSetupStatus ().get (0 ));
40+ assertEquals ("Pluging in the power supply connectors." , standardComputerBuilder .getMotherboardSetupStatus ().get (1 ));
3641 }
37-
42+
3843 @ Test
3944 public void givenStandardProcessor_whenAddingProcessor_thenEqualAssertion () {
40- standardComputer .addProcessor ();
41- assertEquals ("Standard Processor" , standardComputer .getComputerParts ().get ("Processor" ));
45+ standardComputerBuilder .addProcessor ();
46+ assertEquals ("Standard Processor" , standardComputerBuilder .getComputerParts ().get ("Processor" ));
4247 }
4348
4449 @ Test
4550 public void givenAllStandardParts_whenBuildingComputer_thenTwoParts () {
46- standardComputer .buildComputer ();
47- assertEquals (2 , standardComputer .getComputerParts ().size ());
51+ standardComputerBuilder .buildComputer ();
52+ assertEquals (2 , standardComputerBuilder .getComputerParts ().size ());
4853 }
49-
54+
5055 @ Test
51- public void givenHighEnddMotherBoard_whenAddingMotherBoard_thenEqualAssertion () {
52- highEndComputer .addMotherboard ();
53- Assert .assertEquals ("High-end Motherboard" , highEndComputer .getComputerParts ().get ("Motherboard" ));
56+ public void givenAllStandardParts_whenComputerisBuilt_thenComputerInstance () {
57+ assertThat (standardComputerBuilder .buildComputer (), instanceOf (Computer .class ));
5458 }
5559
60+ @ Test
61+ public void givenHighEnddMotherBoard_whenAddingMotherBoard_thenEqualAssertion () {
62+ highEndComputerBuilder .addMotherboard ();
63+ Assert .assertEquals ("High-end Motherboard" , highEndComputerBuilder .getComputerParts ().get ("Motherboard" ));
64+ }
65+
5666 @ Test
5767 public void givenHighEnddMotheroboard_whenSetup_thenTwoEqualAssertions () {
58- highEndComputer .setupMotherboard ();
59- assertEquals ("Screwing the high-end motherboard to the case." , highEndComputer .getMotherboardSetupStatus ().get (0 ));
60- assertEquals ("Plugin in the power supply connectors." , highEndComputer .getMotherboardSetupStatus ().get (1 ));
68+ highEndComputerBuilder .setupMotherboard ();
69+ assertEquals ("Screwing the high-end motherboard to the case." , highEndComputerBuilder .getMotherboardSetupStatus ().get (0 ));
70+ assertEquals ("Pluging in the power supply connectors." , highEndComputerBuilder .getMotherboardSetupStatus ().get (1 ));
6171 }
62-
72+
6373 @ Test
6474 public void givenHightEndProcessor_whenAddingProcessor_thenEqualAssertion () {
65- highEndComputer .addProcessor ();
66- Assert . assertEquals ("High-end Processor" , highEndComputer .getComputerParts ().get ("Processor" ));
75+ highEndComputerBuilder .addProcessor ();
76+ assertEquals ("High-end Processor" , highEndComputerBuilder .getComputerParts ().get ("Processor" ));
6777 }
6878
6979 @ Test
7080 public void givenAllHighEnddParts_whenBuildingComputer_thenTwoParts () {
71- highEndComputer .buildComputer ();
72- assertEquals (2 , highEndComputer .getComputerParts ().size ());
73- }
81+ highEndComputerBuilder .buildComputer ();
82+ assertEquals (2 , highEndComputerBuilder .getComputerParts ().size ());
83+ }
84+
85+ @ Test
86+ public void givenAllHighEndParts_whenComputerisBuilt_thenComputerInstance () {
87+ assertThat (standardComputerBuilder .buildComputer (), instanceOf (Computer .class ));
88+ }
7489}
0 commit comments