| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,155 @@ | |||
| 1 | + package com.iluwatar.stepbuilder; | ||
| 2 | + | ||
| 3 | + import org.junit.Test; | ||
| 4 | + | ||
| 5 | + import java.util.List; | ||
| 6 | + | ||
| 7 | + import static org.junit.Assert.assertEquals; | ||
| 8 | + import static org.junit.Assert.assertNotNull; | ||
| 9 | + import static org.junit.Assert.assertNull; | ||
| 10 | + import static org.junit.Assert.assertTrue; | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * Date: 12/29/15 - 9:21 PM | ||
| 14 | + * | ||
| 15 | + * @author Jeroen Meulemeester | ||
| 16 | + */ | ||
| 17 | + public class CharacterStepBuilderTest { | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * Build a new wizard {@link Character} and verify if it has the expected attributes | ||
| 21 | + */ | ||
| 22 | + @Test | ||
| 23 | + public void testBuildWizard() { | ||
| 24 | + final Character character = CharacterStepBuilder.newBuilder() | ||
| 25 | + .name("Merlin") | ||
| 26 | + .wizardClass("alchemist") | ||
| 27 | + .withSpell("poison") | ||
| 28 | + .withAbility("invisibility") | ||
| 29 | + .withAbility("wisdom") | ||
| 30 | + .noMoreAbilities() | ||
| 31 | + .build(); | ||
| 32 | + | ||
| 33 | + assertEquals("Merlin", character.getName()); | ||
| 34 | + assertEquals("alchemist", character.getWizardClass()); | ||
| 35 | + assertEquals("poison", character.getSpell()); | ||
| 36 | + assertNotNull(character.toString()); | ||
| 37 | + | ||
| 38 | + final List<String> abilities = character.getAbilities(); | ||
| 39 | + assertNotNull(abilities); | ||
| 40 | + assertEquals(2, abilities.size()); | ||
| 41 | + assertTrue(abilities.contains("invisibility")); | ||
| 42 | + assertTrue(abilities.contains("wisdom")); | ||
| 43 | + | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * Build a new wizard {@link Character} without spell or abilities and verify if it has the | ||
| 48 | + * expected attributes | ||
| 49 | + */ | ||
| 50 | + @Test | ||
| 51 | + public void testBuildPoorWizard() { | ||
| 52 | + final Character character = CharacterStepBuilder.newBuilder() | ||
| 53 | + .name("Merlin") | ||
| 54 | + .wizardClass("alchemist") | ||
| 55 | + .noSpell() | ||
| 56 | + .build(); | ||
| 57 | + | ||
| 58 | + assertEquals("Merlin", character.getName()); | ||
| 59 | + assertEquals("alchemist", character.getWizardClass()); | ||
| 60 | + assertNull(character.getSpell()); | ||
| 61 | + assertNull(character.getAbilities()); | ||
| 62 | + assertNotNull(character.toString()); | ||
| 63 | + | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * Build a new wizard {@link Character} and verify if it has the expected attributes | ||
| 68 | + */ | ||
| 69 | + @Test | ||
| 70 | + public void testBuildWeakWizard() { | ||
| 71 | + final Character character = CharacterStepBuilder.newBuilder() | ||
| 72 | + .name("Merlin") | ||
| 73 | + .wizardClass("alchemist") | ||
| 74 | + .withSpell("poison") | ||
| 75 | + .noAbilities() | ||
| 76 | + .build(); | ||
| 77 | + | ||
| 78 | + assertEquals("Merlin", character.getName()); | ||
| 79 | + assertEquals("alchemist", character.getWizardClass()); | ||
| 80 | + assertEquals("poison", character.getSpell()); | ||
| 81 | + assertNull(character.getAbilities()); | ||
| 82 | + assertNotNull(character.toString()); | ||
| 83 | + | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * Build a new warrior {@link Character} and verify if it has the expected attributes | ||
| 89 | + */ | ||
| 90 | + @Test | ||
| 91 | + public void testBuildWarrior() { | ||
| 92 | + final Character character = CharacterStepBuilder.newBuilder() | ||
| 93 | + .name("Cuauhtemoc") | ||
| 94 | + .fighterClass("aztec") | ||
| 95 | + .withWeapon("spear") | ||
| 96 | + .withAbility("speed") | ||
| 97 | + .withAbility("strength") | ||
| 98 | + .noMoreAbilities() | ||
| 99 | + .build(); | ||
| 100 | + | ||
| 101 | + assertEquals("Cuauhtemoc", character.getName()); | ||
| 102 | + assertEquals("aztec", character.getFighterClass()); | ||
| 103 | + assertEquals("spear", character.getWeapon()); | ||
| 104 | + assertNotNull(character.toString()); | ||
| 105 | + | ||
| 106 | + final List<String> abilities = character.getAbilities(); | ||
| 107 | + assertNotNull(abilities); | ||
| 108 | + assertEquals(2, abilities.size()); | ||
| 109 | + assertTrue(abilities.contains("speed")); | ||
| 110 | + assertTrue(abilities.contains("strength")); | ||
| 111 | + | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * Build a new wizard {@link Character} without weapon and abilities and verify if it has the | ||
| 116 | + * expected attributes | ||
| 117 | + */ | ||
| 118 | + @Test | ||
| 119 | + public void testBuildPoorWarrior() { | ||
| 120 | + final Character character = CharacterStepBuilder.newBuilder() | ||
| 121 | + .name("Poor warrior") | ||
| 122 | + .fighterClass("none") | ||
| 123 | + .noWeapon() | ||
| 124 | + .build(); | ||
| 125 | + | ||
| 126 | + assertEquals("Poor warrior", character.getName()); | ||
| 127 | + assertEquals("none", character.getFighterClass()); | ||
| 128 | + assertNull(character.getWeapon()); | ||
| 129 | + assertNull(character.getAbilities()); | ||
| 130 | + assertNotNull(character.toString()); | ||
| 131 | + | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + /** | ||
| 135 | + * Build a new warrior {@link Character} without any abilities, but with a weapon and verify if it | ||
| 136 | + * has the expected attributes | ||
| 137 | + */ | ||
| 138 | + @Test | ||
| 139 | + public void testBuildWeakWarrior() { | ||
| 140 | + final Character character = CharacterStepBuilder.newBuilder() | ||
| 141 | + .name("Weak warrior") | ||
| 142 | + .fighterClass("none") | ||
| 143 | + .withWeapon("Slingshot") | ||
| 144 | + .noAbilities() | ||
| 145 | + .build(); | ||
| 146 | + | ||
| 147 | + assertEquals("Weak warrior", character.getName()); | ||
| 148 | + assertEquals("none", character.getFighterClass()); | ||
| 149 | + assertEquals("Slingshot", character.getWeapon()); | ||
| 150 | + assertNull(character.getAbilities()); | ||
| 151 | + assertNotNull(character.toString()); | ||
| 152 | + | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments