1+ package com .iluwatar .specification .creature ;
2+
3+ import com .iluwatar .specification .property .Color ;
4+ import com .iluwatar .specification .property .Movement ;
5+ import com .iluwatar .specification .property .Size ;
6+
7+ import org .junit .Test ;
8+ import org .junit .runner .RunWith ;
9+ import org .junit .runners .Parameterized ;
10+
11+ import java .util .Arrays ;
12+ import java .util .Collection ;
13+
14+ import static org .junit .Assert .assertEquals ;
15+ import static org .junit .Assert .assertNotNull ;
16+
17+ /**
18+ * Date: 12/29/15 - 7:47 PM
19+ *
20+ * @author Jeroen Meulemeester
21+ */
22+ @ RunWith (Parameterized .class )
23+ public class CreatureTest {
24+
25+ /**
26+ * @return The tested {@link Creature} instance and its expected specs
27+ */
28+ @ Parameterized .Parameters
29+ public static Collection <Object []> data () {
30+ return Arrays .asList (
31+ new Object []{new Dragon (), "Dragon" , Size .LARGE , Movement .FLYING , Color .RED },
32+ new Object []{new Goblin (), "Goblin" , Size .SMALL , Movement .WALKING , Color .GREEN },
33+ new Object []{new KillerBee (), "KillerBee" , Size .SMALL , Movement .FLYING , Color .LIGHT },
34+ new Object []{new Octopus (), "Octopus" , Size .NORMAL , Movement .SWIMMING , Color .DARK },
35+ new Object []{new Shark (), "Shark" , Size .NORMAL , Movement .SWIMMING , Color .LIGHT },
36+ new Object []{new Troll (), "Troll" , Size .LARGE , Movement .WALKING , Color .DARK }
37+ );
38+ }
39+
40+ /**
41+ * The tested creature
42+ */
43+ private final Creature testedCreature ;
44+
45+ /**
46+ * The expected name of the tested creature
47+ */
48+ private final String name ;
49+
50+ /**
51+ * The expected size of the tested creature
52+ */
53+ private final Size size ;
54+
55+ /**
56+ * The expected movement type of the tested creature
57+ */
58+ private final Movement movement ;
59+
60+ /**
61+ * The expected color of the tested creature
62+ */
63+ private final Color color ;
64+
65+ /**
66+ * @param testedCreature The tested creature
67+ * @param name The expected name of the creature
68+ * @param size The expected size of the creature
69+ * @param movement The expected movement type of the creature
70+ * @param color The expected color of the creature
71+ */
72+ public CreatureTest (final Creature testedCreature , final String name , final Size size ,
73+ final Movement movement , final Color color ) {
74+ this .testedCreature = testedCreature ;
75+ this .name = name ;
76+ this .size = size ;
77+ this .movement = movement ;
78+ this .color = color ;
79+ }
80+
81+
82+ @ Test
83+ public void testGetName () throws Exception {
84+ assertEquals (this .name , this .testedCreature .getName ());
85+ }
86+
87+ @ Test
88+ public void testGetSize () throws Exception {
89+ assertEquals (this .size , this .testedCreature .getSize ());
90+ }
91+
92+ @ Test
93+ public void testGetMovement () throws Exception {
94+ assertEquals (this .movement , this .testedCreature .getMovement ());
95+ }
96+
97+ @ Test
98+ public void testGetColor () throws Exception {
99+ assertEquals (this .color , this .testedCreature .getColor ());
100+ }
101+
102+ @ Test
103+ public void testToString () throws Exception {
104+ final String toString = this .testedCreature .toString ();
105+ assertNotNull (toString );
106+ assertEquals (
107+ String .format ("%s [size=%s, movement=%s, color=%s]" , name , size , movement , color ),
108+ toString
109+ );
110+ }
111+ }
0 commit comments