1+ package com .iluwatar .servant ;
2+
3+ import org .junit .Test ;
4+
5+ import java .util .ArrayList ;
6+
7+ import static org .junit .Assert .*;
8+ import static org .mockito .Mockito .mock ;
9+ import static org .mockito .Mockito .verify ;
10+ import static org .mockito .Mockito .verifyNoMoreInteractions ;
11+ import static org .mockito .Mockito .when ;
12+
13+ /**
14+ * Date: 12/28/15 - 10:02 PM
15+ *
16+ * @author Jeroen Meulemeester
17+ */
18+ public class ServantTest {
19+
20+ @ Test
21+ public void testFeed () throws Exception {
22+ final Royalty royalty = mock (Royalty .class );
23+ final Servant servant = new Servant ("test" );
24+ servant .feed (royalty );
25+ verify (royalty ).getFed ();
26+ verifyNoMoreInteractions (royalty );
27+ }
28+
29+ @ Test
30+ public void testGiveWine () throws Exception {
31+ final Royalty royalty = mock (Royalty .class );
32+ final Servant servant = new Servant ("test" );
33+ servant .giveWine (royalty );
34+ verify (royalty ).getDrink ();
35+ verifyNoMoreInteractions (royalty );
36+ }
37+
38+ @ Test
39+ public void testGiveCompliments () throws Exception {
40+ final Royalty royalty = mock (Royalty .class );
41+ final Servant servant = new Servant ("test" );
42+ servant .giveCompliments (royalty );
43+ verify (royalty ).receiveCompliments ();
44+ verifyNoMoreInteractions (royalty );
45+ }
46+
47+ @ Test
48+ public void testCheckIfYouWillBeHanged () throws Exception {
49+ final Royalty goodMoodRoyalty = mock (Royalty .class );
50+ when (goodMoodRoyalty .getMood ()).thenReturn (true );
51+
52+ final Royalty badMoodRoyalty = mock (Royalty .class );
53+ when (badMoodRoyalty .getMood ()).thenReturn (true );
54+
55+ final ArrayList <Royalty > goodCompany = new ArrayList <>();
56+ goodCompany .add (goodMoodRoyalty );
57+ goodCompany .add (goodMoodRoyalty );
58+ goodCompany .add (goodMoodRoyalty );
59+
60+ final ArrayList <Royalty > badCompany = new ArrayList <>();
61+ goodCompany .add (goodMoodRoyalty );
62+ goodCompany .add (goodMoodRoyalty );
63+ goodCompany .add (badMoodRoyalty );
64+
65+ assertTrue (new Servant ("test" ).checkIfYouWillBeHanged (goodCompany ));
66+ assertTrue (new Servant ("test" ).checkIfYouWillBeHanged (badCompany ));
67+
68+ }
69+
70+ }
0 commit comments