|
| 1 | +package com.baeldung.templatemethodpatterntest; |
| 2 | + |
| 3 | +import com.baeldung.templatemethodpattern.model.HighEndComputer; |
| 4 | +import com.baeldung.templatemethodpattern.model.StandardComputer; |
| 5 | +import org.junit.Assert; |
| 6 | +import org.junit.BeforeClass; |
| 7 | +import org.junit.Test; |
| 8 | + |
| 9 | +public class TemplateMethodPatternTest { |
| 10 | + |
| 11 | + private static StandardComputer standardComputer; |
| 12 | + private static HighEndComputer highEndComputer; |
| 13 | + |
| 14 | + @BeforeClass |
| 15 | + public static void setUpStandardComputerInstance() { |
| 16 | + standardComputer = new StandardComputer(); |
| 17 | + } |
| 18 | + |
| 19 | + @BeforeClass |
| 20 | + public static void setUpHighEndComputerInstance() { |
| 21 | + highEndComputer = new HighEndComputer(); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + public void givenStandardProcessor_whenAddingProcessor_thenEqualAssertion() { |
| 26 | + standardComputer.addProcessor(); |
| 27 | + Assert.assertEquals("Standard Processor", standardComputer |
| 28 | + .getComputerParts().get("Processor")); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void givenStandardMotherBoard_whenAddingMotherBoard_thenEqualAssertion() { |
| 33 | + standardComputer.addMotherboard(); |
| 34 | + Assert.assertEquals("Standard Motherboard", standardComputer |
| 35 | + .getComputerParts().get("Motherboard")); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void givenStandardMemory_whenAddingMemory_thenEqualAssertion() { |
| 40 | + standardComputer.addMemory(); |
| 41 | + Assert.assertEquals("8GB", standardComputer |
| 42 | + .getComputerParts().get("Memory")); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void givenStandardHardDrive_whenAddingHardDrive_thenEqualAssertion() { |
| 47 | + standardComputer.addHardDrive(); |
| 48 | + Assert.assertEquals("1TB Hard Drive", standardComputer |
| 49 | + .getComputerParts().get("Hard Drive")); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void givenStandardGraphicaCard_whenAddingGraphicCard_thenEqualAssertion() { |
| 54 | + standardComputer.addGraphicCard(); |
| 55 | + Assert.assertEquals("Standard Graphic Card", standardComputer |
| 56 | + .getComputerParts().get("Graphic Card")); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void givenStandardSoundCard_whenAddingSoundCard_thenEqualAssertion() { |
| 61 | + standardComputer.addSoundCard(); |
| 62 | + Assert.assertEquals("Standard Sound Card", standardComputer |
| 63 | + .getComputerParts().get("Sound Card")); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void givenAllStandardParts_whenBuildingComputer_thenSixParts() { |
| 68 | + standardComputer.buildComputer(); |
| 69 | + Assert.assertEquals(6, standardComputer |
| 70 | + .getComputerParts().size()); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void givenHightEndProcessor_whenAddingProcessor_thenEqualAssertion() { |
| 75 | + highEndComputer.addProcessor(); |
| 76 | + Assert.assertEquals("High End Processor", highEndComputer |
| 77 | + .getComputerParts().get("Processor")); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void givenHighEnddMotherBoard_whenAddingMotherBoard_thenEqualAssertion() { |
| 82 | + highEndComputer.addMotherboard(); |
| 83 | + Assert.assertEquals("High End Motherboard", highEndComputer |
| 84 | + .getComputerParts().get("Motherboard")); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + public void givenHighEndMemory_whenAddingMemory_thenEqualAssertion() { |
| 89 | + highEndComputer.addMemory(); |
| 90 | + Assert.assertEquals("16GB", highEndComputer |
| 91 | + .getComputerParts().get("Memory")); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void givenHighEndHardDrive_whenAddingHardDrive_thenEqualAssertion() { |
| 96 | + highEndComputer.addHardDrive(); |
| 97 | + Assert.assertEquals("2TB Hard Drive", highEndComputer |
| 98 | + .getComputerParts().get("Hard Drive")); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void givenHighEndGraphicCard_whenAddingGraphicCard_thenEqualAssertion() { |
| 103 | + highEndComputer.addGraphicCard(); |
| 104 | + Assert.assertEquals("High End Graphic Card", highEndComputer |
| 105 | + .getComputerParts().get("Graphic Card")); |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + public void givenHighEndSoundCard_whenAddingSoundCard_thenEqualAssertion() { |
| 110 | + highEndComputer.addSoundCard(); |
| 111 | + Assert.assertEquals("High End Sound Card", highEndComputer |
| 112 | + .getComputerParts().get("Sound Card")); |
| 113 | + } |
| 114 | + |
| 115 | + @Test |
| 116 | + public void givenAllHighEndParts_whenBuildingComputer_thenSixParts() { |
| 117 | + highEndComputer.buildComputer(); |
| 118 | + Assert.assertEquals(6, highEndComputer.getComputerParts().size()); |
| 119 | + } |
| 120 | +} |
0 commit comments