I'm trying to test when the Game
class is instantiated, that the start
method is called. However I get the following error:
Wanted but not invoked:
game.start();
Actually, there were zero interactions with this mock.
I have the following class called Game
public class Game {
private Hand player_hand;
private Hand dealer_hand;
public static Boolean isInPlay;
public Game() {
player_hand = new Hand();
dealer_hand = new Hand();
start();
}
public void start() {
isInPlay = true;
player_hand.hit();
player_hand.hit();
System.out.println("Player hand: ");
player_hand.printHands();
instantWinLose();
dealer_hand.hit();
dealer_hand.hit();
}
}
I have a test class called GameTest
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class GameTest {
@InjectMocks
Game game;
@Mock
Hand hand;
@Test
public void testGameConstruction() {
Game mockedGame = mock(Game.class);
verify(mockedGame, times(1)).start();
}
}
I'm new to Mockito. I've tried following examples in Difference between @Mock and @InjectMocks but I still get the same error