1+ package com .iluwatar .builder ;
2+
3+ import org .junit .Test ;
4+
5+ import static org .junit .Assert .assertEquals ;
6+ import static org .junit .Assert .assertNotNull ;
7+
8+ /**
9+ * Date: 12/6/15 - 11:01 PM
10+ *
11+ * @author Jeroen Meulemeester
12+ */
13+ public class HeroTest {
14+
15+ /**
16+ * Test if we get the expected exception when trying to create a hero without a profession
17+ */
18+ @ Test (expected = IllegalArgumentException .class )
19+ public void testMissingProfession () throws Exception {
20+ new Hero .HeroBuilder (null , "Sir without a job" );
21+ }
22+
23+ /**
24+ * Test if we get the expected exception when trying to create a hero without a name
25+ */
26+ @ Test (expected = IllegalArgumentException .class )
27+ public void testMissingName () throws Exception {
28+ new Hero .HeroBuilder (Profession .THIEF , null );
29+ }
30+
31+ /**
32+ * Test if the hero build by the builder has the correct attributes, as requested
33+ */
34+ @ Test
35+ public void testBuildHero () throws Exception {
36+ final String heroName = "Sir Lancelot" ;
37+
38+ final Hero hero = new Hero .HeroBuilder (Profession .WARRIOR , heroName )
39+ .withArmor (Armor .CHAIN_MAIL )
40+ .withWeapon (Weapon .SWORD )
41+ .withHairType (HairType .LONG_CURLY )
42+ .withHairColor (HairColor .BLOND )
43+ .build ();
44+
45+ assertNotNull (hero );
46+ assertNotNull (hero .toString ());
47+ assertEquals (Profession .WARRIOR , hero .getProfession ());
48+ assertEquals (heroName , hero .getName ());
49+ assertEquals (Armor .CHAIN_MAIL , hero .getArmor ());
50+ assertEquals (Weapon .SWORD , hero .getWeapon ());
51+ assertEquals (HairType .LONG_CURLY , hero .getHairType ());
52+ assertEquals (HairColor .BLOND , hero .getHairColor ());
53+
54+ }
55+
56+ }
0 commit comments